微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ggplot的堆积条形图问题

如何解决ggplot的堆积条形图问题

我非常感谢您为单个x值创建堆叠的条形图的帮助。我在创建它方面取得了一些成功,但是我想用s变量替换图右侧的图例,并使颜色更加鲜明。参见图片以供参考。

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

Image of chart as it stands

解决方法

我认为您只需要:

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

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。