在ggplot中调整geom_bar(position ="dodge") [英] Adjusting geom_bar (position="dodge") in ggplot
本文介绍了在ggplot中调整geom_bar(position ="dodge")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在ggplot中创建一个2变量条形图,其中一种度量部分隐藏在另一种度量之后.我可以使用Series Overlap在Excel中完成此操作,并获得此结果.
I want to create a 2 variable bar chart in ggplot where one measure is partially hidden behind the other. I can do it in Excel using Series Overlap and get this result.
使用geom_bar(position ="dodge")将两个条并排放置.有办法完全调整吗?
Using the geom_bar (position="dodge") places the two bars side by side. Is there a way to adjust this at all?
一些代码:
library (ggplot2)
library(reshape2)
x <- c(19, 18, 21, 19)
y <- c(17, 16, 18, 19)
z <- c("a", "b", "c", "d")
df <- melt (data.frame (x,y,z))
ggplot (df, aes(x=z, y=value, fill=variable)) + geom_bar (stat="identity", position ="dodge")
推荐答案
您可以通过指定position = position_dodge(...)
来自定义躲避.
You can customise the dodging by specifying position = position_dodge(...)
.
ggplot (df, aes(x=z, y=value, fill=variable)) +
geom_bar (stat="identity", position = position_dodge(width = 0.5))
这篇关于在ggplot中调整geom_bar(position ="dodge")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文