2016-09-12 80 views
-1

假设有以下数据:ggplot geom_bar绘制百分

    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。我知道图表中的值不匹配,只是草稿。

+0

的可能的复制[创建R中堆积%的barplot(http://stackoverflow.com/questions/9563368/create-stacked-percent-barplot- in-r) – Axeman

+0

谢谢,但我认为情况并非如此。我有百分位值,这个问题基本上是用饼图表示的,但是用百分比表示百分比,而不是对应于特定百分比的数量。 –

+1

那好吧,你能告诉我们你到目前为止所尝试过的,以及它出错的地方吗? – Axeman

回答

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"))