[英]Adjusting geom_bar (position=“dodge”) in ggplot
我想在 ggplot 中創建一個 2 個變量條形圖,其中一個度量部分隱藏在另一個度量后面。 我可以在 Excel 中使用 Series Overlap 來完成並得到這個結果。
使用 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")
您可以通過指定position = position_dodge(...)
來自定義閃避。
ggplot (df, aes(x=z, y=value, fill=variable)) +
geom_bar (stat="identity", position = position_dodge(width = 0.5))
我在上面的幫助下解決了它,但進一步調整:
ggplot (df, aes(x=z, y=value, fill=variable)) +
geom_bar (stat="identity", position = position_dodge2(width = 0.5, preserve = "single", padding = -0.5))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.