Til*_*und 4 r ggplot2 r-maptools rgdal hmisc
我是R的新手,不知道如何使用ggplot2绘制两个data.frames.我收到以下错误消息:Error: ggplot2 doesn't know how to deal with data of class uneval
如何将我的数据与基础世界地图放在一起?
这是我的代码:
require(Hmisc)
require(mapproj)
require(ggplot2)
require(rgdal)
require(maptools)
require(sp)
require(cshapes)
gpclibPermit()
world <- cshp(date=as.Date("2008-1-1"))
world.points <- fortify(world, region='COWCODE')
p <- ggplot(world.points, aes(long,lat,group=group)) + geom_polygon()
dat <- mdb.get("CLIWOC15_2000.mdb") # you can get the data from here: http://pendientedemigracion.ucm.es/info/cliwoc/cliwoc15.htm
tmp <- dat$CLIWOC15[,c("Lon3","Lat3")]
ggplot(world.points,aes(long,lat,group=group))
+geom_polygon()
+geom_point()
+geom_histogram(tmp,aes(Lon3,Lat3),alpha=0.01,size=1)
+coord_map()+ylim(-90,90)
Run Code Online (Sandbox Code Playgroud)
如果使用多个数据集,请尝试从
函数中拉出data和aes信息,ggplot并geom_*根据需要将其放入每个对象中.
ggplot() +
geom_polygon(data=world.points,aes(long,lat,group=group)) +
geom_point(data=world.points,aes(long,lat,group=group)) +
# Separately, I'm not sure what the intended outcome is for this histogram, but it doesn't appear to be of a correct form
geom_histogram(data=tmp,aes(Lon3,Lat3),alpha=0.01,size=1) +
coord_map() +
ylim(-90,90)
Run Code Online (Sandbox Code Playgroud)
请注意,虽然函数的第一个参数ggplot(.)是data,但对于大多数(任何?)而言,情况并非如此geom_*.他们的第一个论点是mapping.
因此,如果您使用的第一个参数是数据集,请确保将其命名为明确,
即geom_point(data=myDataFrame, .)
# You can always check the arguments by using the `args(.)` function
> args(ggplot)
function (data = NULL, ...)
NULL
> args(geom_polygon)
function (mapping = NULL, data = NULL, stat = "identity", position = "identity", ...)
NULL
> args(geom_histogram)
function (mapping = NULL, data = NULL, stat = "bin", position = "stack", ...)
NULL
Run Code Online (Sandbox Code Playgroud)