我想在每种颜色的列中添加趋势线,如下所示:What I want to have
这个是可能的吗?我尝试过使用geom_line(),但它不允许我这样做,因为您需要与条形图具有相同数量的点。这是我当前的代码:
library(ggplot2)
library(reshape)
o2concplot <- melt(o2conctable[,c('years','mino2conc','meano2conc','maxo2conc')],id.vars = 1)
ggplot(o2concplot,aes(x = years, y = value)) + geom_bar(aes(fill = variable),stat = "identity", position = "dodge") + labs(title = "Ocean Dissolved O[2] changes 2008-2018*", x = "Year", y = "Dissolved O[2] (μmolL^-1)", caption = "*Based on data from IMOS") + scale_fill_manual(name = "Key", labels = c("Minimum", "Mean", "Maximum"), values = c("cornflower blue", "light green", "coral2")) + scale_x_continuous(breaks = c(2008, 2009, 2010, 2015, 2017, 2018))
发布于 2020-04-11 20:39:19
您可以在aes中尝试使用group。
您可以使用官方文档here
h <- ggplot(nlme::Oxboys, aes(age, height))
# A single line tries to connect all the observations
h + geom_line()给出

h + geom_line(aes(group = Subject))给出

https://stackoverflow.com/questions/61156532
复制相似问题