[英]Unusual behavior of ggplot2 0.9.3
This code does not work as expected with ggplot2 0.9.3
(worked fine with earlier versions of ggplot2, See here ).此代码在
ggplot2 0.9.3
中无法正常工作(与ggplot2 0.9.3
早期版本一起工作正常,请参见此处)。 Is there a work-around for this problem?这个问题有解决方法吗?
library(ggplot2)
p <- qplot(as.factor(dose), len, data=ToothGrowth, geom = "boxplot", color = supp) + theme_bw()
p <- p + labs(x="Dose", y="Response")
p <- p + stat_summary(fun.y = mean, geom = "point", color = "blue", aes(group=supp))
p <- p + stat_summary(fun.y = mean, geom = "line", aes(group = supp))
p <- p + theme(axis.title.x = element_text(size = 12, hjust = 0.54, vjust = 0))
p <- p + theme(axis.title.y = element_text(size = 12, angle = 90, vjust = 0.25))
print(p)
This line这条线
p <- p + stat_summary(fun.y = mean, geom = "line", aes(group = supp))
produces the following warning产生以下警告
geom_path: Each group consist of only one observation.
geom_path:每组只包含一个观察。 Do you need to adjust the group aesthetic?
你需要调整群体审美吗?
This behavior is a bug in ggplot2 0.9.3: https://github.com/hadley/ggplot2/issues/739这种行为是 ggplot2 0.9.3 中的一个错误: https : //github.com/hadley/ggplot2/issues/739
You can work around it by calculating the summaries using ddply:您可以通过使用 ddply 计算摘要来解决它:
library(plyr)
tg <- ddply(ToothGrowth, c("dose", "supp"), summarise, len = mean(len))
library(ggplot2)
ggplot(ToothGrowth, aes(x=as.factor(dose), y=len, colour=supp)) +
geom_boxplot() +
geom_line(data=tg, aes(group=supp))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.