将点添加到ggplot2中的geom_tile图层 [英] Adding points to a geom_tile layer in ggplot2
本文介绍了将点添加到ggplot2中的geom_tile图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
volcano3d < - melt(volcano)
names(volcano3d)< - c (x,y,z)
pts < - data.frame(a = runif(10,0,80),b = runif(10,0,60))
v< - ggplot(volcano3d,aes(x,y,z = z))
v + geom_tile(aes(fill = z))
#正常工作
v + geom_tile(aes(fill = z))+ geom_point(data = pts,aes(x = a,y = b))
eval中的错误(expr,envir,enclos):object'z'找不到
有什么想法吗?
解决方案
要么将z美学与
v + geom_tile(aes(fill = b))+ geom_point(data = pts,aes(x = a,y = b,z = NULL))
或简单地将它从第一个ggplot调用中移除
v < - ggplot(volcano3d,aes(x, y))
v + geom_tile(aes(fill = z))+ geom_point(data = pts,aes(x = a,y = b))
In R 2.13.1 / ggplot2 0.8.9, I'm trying to add points onto a geom_tile layer. This example reproduces the error.
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")
pts <- data.frame(a=runif(10,0,80), b=runif(10,0,60))
v <- ggplot(volcano3d, aes(x, y, z = z))
v + geom_tile(aes(fill = z))
# works fine
v + geom_tile(aes(fill = z)) + geom_point(data=pts, aes(x=a, y=b))
# Error in eval(expr, envir, enclos) : object 'z' not found
Any idea on what is wrong?
解决方案
either unmap the z aesthetics with
v + geom_tile(aes(fill = z)) + geom_point(data=pts, aes(x=a, y=b,z=NULL) )
or simply remove it from the first ggplot call
v <- ggplot(volcano3d, aes(x, y))
v + geom_tile(aes(fill = z)) + geom_point(data=pts, aes(x=a, y=b))
这篇关于将点添加到ggplot2中的geom_tile图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文