【问题标题】:ggplot2 two data.frames, doesn't know how to deal with data of class uneval [duplicate]ggplot2 两个data.frames,不知道如何处理 uneval 类的数据 [重复]
【发布时间】:2013-05-06 17:11:58
【问题描述】:

我是 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)

【问题讨论】:

  • 基本上,在你的直方图中使用data = tmp,或者在aes()之后放置tmp

标签: r ggplot2 rgdal hmisc maptools


【解决方案1】:

如果使用多个数据集,请尝试从 ggplot 中提取 dataaes 信息 函数并根据需要将其放入每个 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)

关于论点

请注意,虽然函数 ggplot(.) 的第一个参数是 data,但这不是 大多数(任何?)geom_*s 的情况。他们的第一个参数是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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多