我想在ggplot中创建一个2变量条形图,其中一个度量部分隐藏在另一个之后.我可以使用Series Overlap在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")
Run Code Online (Sandbox Code Playgroud)
ori*_*zon 18
您可以通过指定来自定义闪避position = position_dodge(...).
ggplot (df, aes(x=z, y=value, fill=variable)) +
geom_bar (stat="identity", position = position_dodge(width = 0.5))
Run Code Online (Sandbox Code Playgroud)
