मैं पहलुओं के साथ एक वन भूखंड का उत्पादन करने की कोशिश कर रहा हूँ R
, जहां y कुल्हाड़ियों पैमाने मुक्त हैं। लेकिन मैं मुसीबत में चल रहा हूँ।
यहाँ मेरा उदाहरण डेटा है:
set.seed(1)
df <- data.frame(y=rnorm(10),x=c(1:5,1:3,1:2),group=c(rep("a",5),rep("b",3),rep("c",2)),name=c(paste("a",1:5,sep=""),paste("b",1:3,sep=""),paste("c",1:2,sep="")))
df$ymin <- df$y-runif(10,0.5,0.7)
df$ymax <- df$y+runif(10,0.5,0.7)
अगर मैं उपयोग करता हूं:
p <- ggplot(df,aes(y=y,x=x,ymin=ymin,ymax=ymax))+geom_point()+coord_flip()+scale_y_discrete(limits=df$name)+facet_wrap(~group,ncol=3,scales="free")+geom_vline(lty=2,aes(xintercept=0,colour="black"))
मुझे त्रुटि मिलती है:
Error in facet_render.wrap(plot$facet, panel, plot$coordinates, theme, :
ggplot2 does not currently support free scales with a non-cartesian coord or coord_flip.
जिस पर पहले ही एसओ से चर्चा हो चुकी है।
मैन्युअल रूप से कुल्हाड़ियों को फ़्लिप करके इसे हल करने की कोशिश कर रहा है इसलिए ड्रापिंग flip_coord()
भाग, लगभग काम करता है - मुझे त्रुटि पट्टियाँ नहीं मिल रही हैं:
p <- ggplot(df,aes(y=x,x=y,xmin=ymin,xmax=ymax))+geom_point()+scale_y_discrete(limits=df$name)+facet_wrap(~group,ncol=3,scales="free")+geom_vline(lty=2,aes(xintercept=0,colour="black"))
तो मेरा सवाल यह है कि मुझे एरर बार कैसे मिलेगाक्या आप वहां मौजूद हैं? इसके अलावा, अभी y axes don "t नीचे और ऊपर के शीर्ष बिंदुओं के नीचे पर्याप्त स्थान छोड़ता है। प्रत्येक छोर पर थोड़ा सा कैसे जोड़ते हैं ताकि अंक काट नहीं रहे हैं क्योंकि वे अब हैं?
उत्तर:
जवाब के लिए 2 № 1यह कैसा है?
हम प्रयोग कर सकते हैं geom_segment
और सेट करें y
के रूप में समन्वय करें name
p1 <- ggplot(df,aes(y = name, x = y))+
geom_point()+
facet_wrap(~group,ncol=3,scales="free")+
geom_segment(aes(x = ymin, xend = ymax, yend = name))+
geom_vline(lty=2, aes(xintercept=0), colour = "red")
p1