我想在ggplot中创建一个双变量条形图,其中一个度量部分隐藏在另一个度量后面。在Excel中,我可以使用序列重叠来完成这个操作,并得到这个结果。
使用geom_bar (position="dodge")
将两个条形图并排放置。是否有任何方法可以调整此设置?
一些代码:
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")