我想在条形图上方添加一条水平线。目前,我可以使用geom_points
添加点:
data <- ddply(diamonds, .(cut, color), summarise, mean_carat = mean(carat))
ggplot(data, aes(color, mean_carat,fill=cut)) +
geom_bar(stat="identity", position="dodge") +
geom_point(data=data, aes(color, mean_carat, fill=cut))
下图中的红色箭头显示了我要添加的内容:
谢谢!
答案 0 :(得分:5)
尝试添加类似
的内容data <- ddply(diamonds, .(cut, color), summarise, mean_carat = mean(carat))
data2 <- ddply(data, ~color, summarise, max_carat = max(mean_carat))
C <- merge(data,data2, by = c('color'))
ggplot(data, aes(color, mean_carat,fill=cut)) +
geom_bar(stat="identity", position="dodge") +
geom_point(data=data, aes(color, mean_carat)) +
geom_errorbar(data = C, aes(y=max_carat, ymax=max_carat, ymin=max_carat))