[英]How to make a bar plot of my data frame using ggplot2()?
I am trying to create a bar plot using ggplot() function. 我正在尝试使用ggplot()函数创建条形图。 I have this data frame: 我有这个数据框:
25% - 75% 5% - 95% Out of Confidence Band leadtime
1 49.91055 89.80322 10.196780 2 hr
2 50.08945 89.80322 10.196780 12 hr
3 49.73166 89.80322 10.196780 24 hr
4 49.91055 90.16100 9.838998 32 hr
5 50.08945 89.80322 10.196780 50 hr
6 49.73166 89.62433 10.375671 62 hr
I want to show for every Leadtime its three respective values (25-75%, 5-95%, Out of confidence Band) in bars. 我想为每个Leadtime显示其三个相应的值(25-75%,5-95%,超出置信度带),以条形表示。 So at the end I will have 6 group of bars. 因此,最后我将有6组酒吧。
Thanks in advance guys! 在此先感谢大家!
It's not entirely clear if you want stacked bars, if so - here you go. 您是否想要堆叠的条形还不是很清楚,如果是这样-您可以开始。 I changed the shape of the dataframe to make plotting easier. 我更改了数据框的形状以使绘制更加容易。
dat <- data.frame(leadtime = rep(c(2,12,24,32,50,62),each=3),
percent = rep(c("25-75","5-95", "OoC"), 6),
value = c(49.91055, 89.80322, 10.196780,50.08945, 89.80322, 10.196780,
49.73166, 89.80322, 10.196780, 49.91055, 90.16100, 9.838998, 50.08945,
89.80322, 10.196780, 49.73166, 89.62433, 10.375671))
ggplot(dat, aes(leadtime, value, fill = percent))+geom_bar(stat='identity')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.