简体   繁体   English

ggplot 堆积条形图问题

[英]Stacked Bar Chart Issues with ggplot

I would much appreciate some help to create a stacked bar chart for a single x value.我非常感谢为单个 x 值创建堆积条形图的帮助。 I have had some success creating it, however I would like to replace the legend on the right hand side of the graph with my s variable and make the colour more distinct.我在创建它时取得了一些成功,但是我想用我的 s 变量替换图表右侧的图例,并使颜色更加清晰。 See image for reference.请参阅图像以供参考。

d <- c(287, 76, 237, 44, 249, 149, 3)

s <- c('Allied servicemen reached Spain through the Pyrenees', 
'Civilians reached Spain through the Pyrenees', 
'Airmen who were arrested during their evasion', 
'Airmen who were handed over to other evasion lines', 
'Airmen who were kept in camps of the "Operation Marathon" in France and Belgium', 
'Airmen who were hidden by their lodgers until Liberation', 
'Airmen who were killed during their evasion')

t <- c('Comete Line','Comete Line','Comete Line',
'Comete Line','Comete Line','Comete Line','Comete Line')

Comete_Line <- data.frame(d,s,t)

Comete_Line <- Comete_Line[order(Comete_Line$d),]

Comete_Line.TB %>% 
ggplot(aes(x = t, y = d, fill = d)) + 
geom_bar(stat = "identity", width = 0.2)

图表的现状

I think you just need:我认为你只需要:

    Comete_Line %>% 
      ggplot(aes(x = t, y = d, fill = s)) + 
      geom_bar(stat = "identity", width = 0.2)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM