ggplot

2014-04-01 21 views
5

में geom_bar (स्थिति = "डॉज") समायोजित करना मैं ggplot में एक 2 परिवर्तनीय बार चार्ट बनाना चाहता हूं जहां एक उपाय दूसरे के पीछे आंशिक रूप से छिपा हुआ है। मैं इसे श्रृंखला ओवरलैप का उपयोग कर एक्सेल में कर सकता हूं और this result प्राप्त कर सकता हूं।ggplot

geom_bar (स्थिति = "डॉज") का उपयोग करके दोनों सलाखों को एक तरफ रखता है। क्या इसे समायोजित करने का कोई तरीका है?

कुछ कोड:

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") 

उत्तर

13

आप position = position_dodge(...) निर्दिष्ट द्वारा चकमा दे रहा है अनुकूलित कर सकते हैं।

ggplot (df, aes(x=z, y=value, fill=variable)) + 
    geom_bar (stat="identity", position = position_dodge(width = 0.5)) 

enter image description here

+0

मैं बाहर बात करने के लिए position_dodge'' '' के लिए अनुकूलन की राशि boggling दिमाग है कि चाहते हैं। http://ggplot2.tidyverse.org/reference/geom_bar.html – PatrickT