Error: No Default label placement from this type of ggplot
Error: No Default label placement from this type of ggplot
为什么会出现此错误?这是 R 脚本和我试图绘制 (link to data here) 的盐度等值线的数据集:
看起来像这样(前 10 行):
Longitude Latitude Salinity
1 -76.7027969 35.8915787 0.094745182
2 -76.67744141 35.8915787 0.10131969
3 -76.65208591 35.8915787 0.109281363
4 -76.62673042 35.8915787 0.118873653
5 -76.60137493 35.8915787 0.130326379
6 -76.57601943 35.8915787 0.143826847
7 -76.55066394 35.8915787 0.159496078
8 -76.52530845 35.8915787 0.177391073
9 -76.49995296 35.8915787 0.197562864
10 -76.47459746 35.8915787 0.220200511
ASsalinity <- read.csv("~/ASsalinity.csv")
library("ggplot2")
library("directlabels")
plot1<-ggplot(ASsalinity)+geom_raster(aes(Longitude,Latitude,fill = Salinity),data=ASsalinity)+geom_contour(aes(Longitude,Latitude,z=Salinity),data=ASsalinity)
plot1
但 direct.label 命令抛出此错误:
direct.label (plot2)
如果使用默认值:
Error in (function (geom, p, L, colvar, ...) :
No default label placement for this type of ggplot
如果我指定位置放置:
direct.label (plot2, "bottom.pieces")
我得到一个不同的错误:
'ggproto' is not an exported object from 'namespace:ggplot2'
我做错了什么?
提前致谢。
因此,在 aosmith 的帮助下,我找到了自己问题的答案。关键是升级到 ggplot2 2.1.0,然后使用 stat_contour()
。下面,我更新了我的代码,同时使用 ggmap 2.6.1 添加了底图:
library("ggmap")
library("ggplot2")
library("directlabels")
ASmap3<-get_map(location= c(lon= -76.16,lat=36.08),zoom=9)
plot1<-ggmap(ASmap3)+stat_contour(aes(Longitude,Latitude,z=Salinity,colour=..level..),data=ASsalinity)
direct.label(plot1,"bottom.pieces")
这是地图:
A map of Albemarle Sound, NC, USA with labeled salinity contours
为什么会出现此错误?这是 R 脚本和我试图绘制 (link to data here) 的盐度等值线的数据集: 看起来像这样(前 10 行):
Longitude Latitude Salinity
1 -76.7027969 35.8915787 0.094745182
2 -76.67744141 35.8915787 0.10131969
3 -76.65208591 35.8915787 0.109281363
4 -76.62673042 35.8915787 0.118873653
5 -76.60137493 35.8915787 0.130326379
6 -76.57601943 35.8915787 0.143826847
7 -76.55066394 35.8915787 0.159496078
8 -76.52530845 35.8915787 0.177391073
9 -76.49995296 35.8915787 0.197562864
10 -76.47459746 35.8915787 0.220200511
ASsalinity <- read.csv("~/ASsalinity.csv")
library("ggplot2")
library("directlabels")
plot1<-ggplot(ASsalinity)+geom_raster(aes(Longitude,Latitude,fill = Salinity),data=ASsalinity)+geom_contour(aes(Longitude,Latitude,z=Salinity),data=ASsalinity)
plot1
但 direct.label 命令抛出此错误:
direct.label (plot2)
如果使用默认值:
Error in (function (geom, p, L, colvar, ...) :
No default label placement for this type of ggplot
如果我指定位置放置:
direct.label (plot2, "bottom.pieces")
我得到一个不同的错误:
'ggproto' is not an exported object from 'namespace:ggplot2'
我做错了什么?
提前致谢。
因此,在 aosmith 的帮助下,我找到了自己问题的答案。关键是升级到 ggplot2 2.1.0,然后使用 stat_contour()
。下面,我更新了我的代码,同时使用 ggmap 2.6.1 添加了底图:
library("ggmap")
library("ggplot2")
library("directlabels")
ASmap3<-get_map(location= c(lon= -76.16,lat=36.08),zoom=9)
plot1<-ggmap(ASmap3)+stat_contour(aes(Longitude,Latitude,z=Salinity,colour=..level..),data=ASsalinity)
direct.label(plot1,"bottom.pieces")
这是地图: A map of Albemarle Sound, NC, USA with labeled salinity contours