简体   繁体   English

在条形图中创建单独的列

[英]Creating separate columns within barplot

I have two columns in my data airlines and sentiment (which are coded as zero and one).我的数据航空公司和情绪中有两列(编码为 0 和 1)。 I have created a bar plot with the code below but I would like the zero and ones to be separated into separate boxes.我用下面的代码创建了一个条形 plot 但我希望将零和一分开到单独的框中。 I have used "dodge" but I haven't been able to get it working.我用过“躲闪”,但我无法让它工作。

Thank you for your help in advance!提前谢谢你的帮助!

1 airline               sentiment 
2 Virgin                     0
3 America airways            1
4 Jet Blue                   0
5 Virgin                     1
6 Virgin                     1
7 America airways            0
8 Jet Blue                   1
9 Virgin Virgin               0
10 America airways             0
11 Jet Blue                    1
12 Virgin                      1

The code below results in this plot:下面的代码导致了这个 plot:

enter image description here在此处输入图像描述

ggplot(airline_sentiment, aes(x=airline, y = sentiment)) + geom_bar(stat = "identity", aes(fill = sentiment))+
  ggtitle("") +
   xlab("Airline") + ylab("Frequency") + theme(legend.position = "none")

When I use:当我使用:

#using dodge
ggplot(airline_sentiment, aes(x=airline, y = sentiment, fill = sentiment)) + geom_bar(stat = "identity", position = "dodge")

#using facet wrap
ggplot(airline_sentiment, aes(x=airline, y = sentiment, fill = sentiment)) + geom_bar(stat = "identity") + facet_wrap(~sentiment)

My code doesn't split into columns like you have suggested rather splits like this enter image description here我的代码不会像您建议的那样拆分成列,而是像这样在此处输入图像描述的拆分

Thank you again!再次感谢你!

Not sure what exactly you mean with "different boxes".不确定“不同的盒子”到底是什么意思。 Here two possibilities using just a few rows of your data这里有两种可能性,只使用几行数据

#using dodge
ggplot(airline_sentiment, aes(x=airline, y = sentiment, fill = sentiment)) + geom_bar(stat = "identity", position = "dodge")

#using facet wrap
ggplot(airline_sentiment, aes(x=airline, y = sentiment, fill = sentiment)) + geom_bar(stat = "identity") + facet_wrap(~sentiment)

躲闪

刻面包裹

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

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