ggplot geom_bar绘制百分位数

时间:2016-09-12 07:05:48

标签: r ggplot2 percentile

让我们说拥有以下数据:

                    Journey_category Perc_25 Perc_50  Perc_75 Perc_90 Perc_95
1         Petrol - Urban - 0 - 0,2 l  0,1103  0,5158   3,9672  15,304   23,20
2    Petrol - ExtraUrban - 0 - 0,2 l  0,0737  0,3562   3,5155  14,098   21,07
3       Petrol - HighWay - 0 - 0,2 l 40,5790 49,9807 117,5530 189,179  213,79

我想使用ggplot将其绘制为堆积列,以表示百分位数。

有点像这样:

enter image description here

任何提示?

PD。我知道图表中的值不匹配,它只是一个草稿。

1 个答案:

答案 0 :(得分:0)

我找到了办法:

p <- ggplot(dat_quant, na.rm = T)
p <- p + ggtitle("Idle hours after journey vs charging time needed")
p <- p + labs(x = "Journey category", y = "Idle time after journey (h)")
p <- p + geom_bar(stat = "identity",  aes(x = Journey_category, y = Perc_95, fill = "Perc_95"))
p <- p + geom_bar(stat = "identity",  aes(x = Journey_category, y = Perc_90, fill = "Perc_90"))
p <- p + geom_bar(stat = "identity",  aes(x = Journey_category, y = Perc_75, fill = "Perc_75"))
p <- p + geom_bar(stat = "identity",  aes(x = Journey_category, y = Perc_50, fill = "Perc_50"))
p <- p + geom_bar(stat = "identity",  aes(x = Journey_category, y = Perc_25, fill = "Perc_25"))