我想在每种颜色的列上添加趋势线,如下所示: 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))
答案 0 :(得分:0)
您可以在group
中尝试aes
。
您可以使用官方文档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))
给予