【发布时间】:2020-01-23 16:12:31
【问题描述】:
以下问题: 我有这个数据集
df
Ch V1 V2
A a1 a2
B b1 b2
C c1 c2
....
而 V1 和 V2 是数值。我想为每个 V1 和 V2 值创建一个带有条形图的条形图。 我试过的代码
ggplot(data = df %>% gather(Variable, No., -Ch),
aes(x = reorder(ID,-No.), y = No., fill = Variable)) +
geom_bar(stat = 'identity', position= position_dodge())+
geom_col()+
xlab("Section of industry")+
ylab("No. of occurences")+
theme_classic()+
theme(axis.text.x = element_text(angle = 45, size=1),
plot.title = element_text(hjust = 0.5),
legend.position = "top")+
ggtitle("XXX")
即使使用 position= position_dodge() 它也只会像这样将两个条合并为一个: 知道如何分离或为什么 positon_dodge() 不起作用?我想是因为我以前用过聚集功能?
另一个问题是,Ch 的值太大,所以如果我想以可读的方式显示它们,图形就会“消失”。有没有办法显示这些值(可能将值写成两行)以便显示?
非常感谢!
【问题讨论】: