我似乎在使用 ggplot2 时遇到了问题。
尝试使用 aes_string 绘制箱线图时出现以下错误:
Error: stat_boxplot requires the following missing aesthetics: x, y
下面是一个例子:
x='group'
y='value'
df=data.frame(group=c('A','A','B','B','C','C'),value=c(1,2,3,4,5,6))
ggplot(data=df,aes_string(x,y)) + geom_boxplot() #returns the error
ggplot(data=df,aes(x,y)) + geom_boxplot() #plots nonsense (naturally)
ggplot(data=df,aes(group,value)) + geom_boxplot() #works, but not strings
关于如何使用字符串进行这项工作的任何建议?
最佳答案
aes
允许前两个参数未命名,并假定为 x 和 y(分别); aes_string
没有这个快捷方式,因此所有参数都必须命名。
尝试:
ggplot(data=df,aes_string(x='group',y='value')) + geom_boxplot()
关于r - 将 ggplot2 aes_string 与箱线图一起使用的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267562/