ggplot

2011-11-05 17 views
7

में स्टैक पॉइंट्स मैं ggplot का उपयोग करके डॉटप्लॉट बना रहा हूं जिसमें कोड और डेटा है जो निम्न ग्राफ का उत्पादन करता है।ggplot

ggplot(data=holder, aes(x=Coef, y=CoefShort, colour=factor(Name))) + geom_point() + labs(x="Value", y="Coefficient") + scale_colour_discrete("Model") 

dotplot

उनके overplotting की काफी मात्रा है और मैं डॉट्स के बीच कुछ ऊर्ध्वाधर जुदाई बनाना चाहेंगे। लेकिन इसे व्यवस्थित होना चाहिए, यानी आदेश हमेशा लाल-हरा-नीला होता है।

geom_stack केवल तभी काम करता है जब एक्स मान समान होता है, न कि जब y मान समान होता है। मैंने position_dodge() कर रहे हैं, तो coord_flip() कर रहे हैं, तो विपरीत अक्षों (एक्स और वाई स्वैपिंग) का उपयोग करने की कोशिश की। यह केवल नीचे दिखाए गए सलाखों के साथ काम करता है।

ggplot(data=holder, aes(y=Coef, x=CoefShort, fill=factor(Name))) + geom_bar(position="dodge", aes(ymax=Coef)) + labs(y="Value", x="Coefficient") + scale_fill_discrete("Model") + coord_flip() 

Vertically dodged bar chart

कोई भी विचार प्राप्त करने का तरीका geom_point() साथ stacking? धन्यवाद।

डेटा: geom_point में

structure(list(Coef = c(-3875.46969970703, 7871.08213392282, 1120.33185255098, 1510.13540851347, 1439.07714113149, 1800.92398445336, -3760.05411752962, 8183.74295221482, 1126.98290537184, 1517.99524139857, 1442.73063836897, 1808.03721179571, -90.6507661872817, -71.7225864185226, -103.615416254984, -732.167583256825, -1075.67574987664, -1908.56266462926, -7362.80215630299, 8886.12888250011, 655.767448263926, 848.716877683527, 869.395903077767, 998.254438325812, -211.682481369473, -303.310032581644, -506.1995360406, -978.697664841985, -1440.30190190734, -2325.22236024601, 2625.94998656519, 3573.68798735398, 4217.82910198788, 4534.8789695778, 4967.19941000705, 5072.02764498623, 5419.64684461491), Name = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), CoefShort = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L), .Label = c("(Intercept)", "carat", "Good", "Very Good", "Premium", "Ideal", "E", "F", "G", "H", "I", "J", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF" ), class = "factor")), .Names = c("Coef", "Name", "CoefShort" ), class = "data.frame", row.names = c(NA, -37L))

उत्तर

8

अंक शून्य चौड़ाई है, तो आप dodging की चौड़ाई निर्धारित करने की आवश्यकता:

ggplot(data=holder, aes(y=Coef, x=CoefShort, colour=factor(Name))) + 
    geom_point(position=position_dodge(width = 0.8)) + 
    labs(y="Value", x="Coefficient", colour = "Model") + 
    coord_flip() 

enter image description here

+0

यह कमाल काम करता है। मुझे नहीं लगता कि पूरे coord_flip() भाग के बिना यह संभव है? – Jared

+0

जो मैंने पूछा उससे पहले काम करता है। लेकिन यह पता चला है कि facet_wrap() में coord_flip() scales = "free" के बाद अब ठीक से काम नहीं करता है। – Jared

+0

@jared: क्या आपने 'position_dodge (ऊंचाई = 0.8)' ('चौड़ाई' की बजाय) कोशिश की? – naught101