![](/img/trans.png)
[英]inheritance of aesthetics in ggplot2 0.9.3 & the behavior of annotation_custom
[英]Unusual behavior of ggplot2 0.9.3
此代碼在ggplot2 0.9.3
中無法正常工作(與ggplot2 0.9.3
早期版本一起工作正常,請參見此處)。 這個問題有解決方法嗎?
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)
這條線
p <- p + stat_summary(fun.y = mean, geom = "line", aes(group = supp))
產生以下警告
geom_path:每組只包含一個觀察。 你需要調整群體審美嗎?
這種行為是 ggplot2 0.9.3 中的一個錯誤: https : //github.com/hadley/ggplot2/issues/739
您可以通過使用 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.