首页 > 解决方案 > 在 R 中的 ggplot 2 中使用更多数据帧

问题描述

当我尝试在 ggplot2 中使用多个数据帧时出现错误;错误:mapping必须由aes()

xdf <- data.frame(x=1:3, y=c(18,11,16))
ydf <- data.frame(x=c(5,7), y=c(18,11))

ggplot(xdf, aes(x,y))+ 
  geom_point()+
  geom_point(ydf, aes(x,y) )

这可以解决吗...?

标签: rggplot2

解决方案


您需要指定这ydfdata参数:

ggplot(xdf, aes(x,y))+ 
  geom_point()+
  geom_point(data=ydf, aes(x,y))

推荐阅读