GGPLOT2:两个离散变量列的堆叠条图
我有一个带有三列的数据集(一个分类列和两差变量列)。我想制作一个堆叠的条图,以比较每个类别的两个离散变量的值。但是,我会获得连续的着色,而不是离散的颜色。
可重复的代码
sampleData <- data.frame(grp = c("A","B", "C"),
var_1 = c(15,20, 25),
var_2 = c(12, 13, 20))
sampleData
p <- ggplot(sampleData, aes(x = grp, y = var_1, fill= var_2)) +
geom_bar( stat="identity", position = "fill")+
coord_flip()+ theme_bw()
p
相反,我想要的是
* var2 始终小于其相应的 var1 值特定的类别。
感谢您的帮助!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是,您没有将尖头固定在较长的范围内。
一旦这样做,问题就变得更容易解决。您只需要更改几件事,最著名的是
y
,fill
和位置
变量以使其正常工作。Your problem here is that you haven't fixed your tibble from Wide to Long.
Once you do this, the problem becomes much easier to solve. You only need to change a few things, most notably the
y
,fill
, andposition
variables to make it work.