【发布时间】:2019-04-26 22:47:18
【问题描述】:
是否可以在 ggplot2 中仅对条形图的一部分着色?
我想要横杆之间的彩色区域:“平均每日最大值”和“平均每日最小值”。
这是我的数据:
temperature <- read.table(text = 'X 1 2 3 4 5 6
1 "Highest temperature" 31 40 39 34 39 42
2 "Mean daily maximum" 27 34 32 30 34 35
3 "Mean daily minimum" 26 31 31 30 31 35
4 "Lowest temperature" 18 20 20 20 20 24', header =T)
t <- dcast(melt(temperature), variable~X)
ggplot(t, aes(x=variable,ymin = `Lowest temperature`,
ymax = `Highest temperature`, lower = `Lowest temperature`,
upper = `Highest temperature`, middle = `Mean daily maximum`)) +
geom_boxplot(stat = 'identity') +
xlab('Number') +
ylab('Temperature') +
geom_crossbar(aes(y = `Mean daily maximum` ))+
geom_crossbar(aes(y = `Mean daily minimum`))
【问题讨论】: