在R中的ggplot 2中使用更多数据帧
当我试图在ggplot2中使用多个数据帧时,会出现错误;错误:在R中的ggplot 2中使用更多数据帧,r,ggplot2,R,Ggplot2,当我试图在ggplot2中使用多个数据帧时,会出现错误;错误:映射必须由aes()创建 xdf您需要指定ydf是数据参数: ggplot(xdf, aes(x,y))+ geom_point()+ geom_point(data=ydf, aes(x,y)) 对于需要在ggplot2中处理不同数据的其他人,还有一些附加说明: 如果在函数ggplot中全局定义aes,并且需要相同的美学效果,则无需再次编写它们 ggplot(xdf, aes(x, y)) + geom_point
映射必须由aes()创建
xdf您需要指定ydf
是数据
参数:
ggplot(xdf, aes(x,y))+
geom_point()+
geom_point(data=ydf, aes(x,y))
对于需要在ggplot2
中处理不同数据的其他人,还有一些附加说明:
如果在函数ggplot
中全局定义aes
,并且需要相同的美学效果,则无需再次编写它们
ggplot(xdf, aes(x, y)) +
geom_point() +
geom_point(data = ydf)
如果需要不同的美学,可以设置inherit.aes=FALSE
忽略全局美学
ggplot(xdf, aes(x, y, color = z)) +
geom_point() +
geom_point(data=ydf, aes(y, x), inherit.aes = FALSE)
数据是中的第二个参数,可以显式调用data=ydf
或提供数据作为第二个参数。
ggplot(xdf, aes(x, y, color = z)) +
geom_point() +
geom_point(data=ydf, aes(y, x), inherit.aes = FALSE)