2012-09-07 18 views
6

मैं एक स्टैक्ड geom_area साजिश बनाने की कोशिश कर रहा हूं, लेकिन एक पंक्ति के साथ प्रत्येक क्षेत्र की साजिश (पहले 'लाल' क्षेत्र पर काम करता है लेकिन नीली नहीं) को रेखांकित करना चाहता हूं। यहां मेरा सबसे अच्छा प्रयास है, लेकिन मैं यह नहीं समझ सकता कि लाइन प्रकार को कैसे ढंका हुआ है। विचार?क्षेत्रों और रूपरेखाओं के साथ geom_area साजिश ggplot

example

df= data.frame(Time=as.numeric(strsplit('1939 1949 1959 1969 1979 1989 1999 2009 2019 2029 2039 2049 1939 1949 1959 1969 1979 1989 1999 2009 2019 2029 2039 2049', split=' ')[[1]]), 
       Acres=as.numeric(strsplit('139504.2 233529.0 392105.3 502983.9 685159.9 835594.7 882945.1 1212671.4 1475211.9 1717971.7 1862505.7 1934308.0 308261.4 502460.8 834303.1 1115150.7 1430797.8 1712085.8 1973366.1 1694907.7 1480506.0 1280047.6 1164200.5 1118045.3', split=' ')[[1]]), 
       WUClass= strsplit('DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban DenseUrban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban Urban', split=' ')[[1]] 
       ) 

a=ggplot(df,aes(x = Time,y = Acres,fill=WUClass))+ geom_area(position = 'stack' ) 
plot(a) 
a+ geom_line(aes(position = 'stack')) 

उत्तर

7

क्षेत्र के लिए एक रूपरेखा को जोड़ने के लिए, बस colour बदलने के लिए:

ggplot(df,aes(x = Time,y = Acres,fill=WUClass)) + 
    geom_area(position = 'stack') + 
    geom_area(position = 'stack', colour="black", show_guide=FALSE) 

लेकिन लाइनों आकर्षित करने के लिए, ऐसा करते हैं:

ggplot(df,aes(x = Time, y = Acres, fill=WUClass, group=WUClass)) + 
    geom_area() + geom_line(aes(ymax=Acres), position="stack") 

enter image description here

3

मैंने अंतर को स्पष्ट करने के लिए लाइन चौड़ाई वास्तव में बड़ी बना दी है।

ggplot(df,aes(x = Time, y = Acres, fill = WUClass)) + 
geom_area(position = 'stack', linetype = 1, size =2 ,colour="black" , 
show_guide=FALSE) + 
geom_line(aes(position = 'stack')) 

enter image description here

+0

धन्यवाद मायासोरा! हालांकि मुझे अन्य लोगों को कुछ और जवाब देना पसंद है क्योंकि मुझे किंवदंती में लाइनों के बारे में चिंता करने की ज़रूरत नहीं है – mmann1123

3

त्रुटि था सिर्फ इतना है कि आप स्थिति डाल रहे थे = एईएस के अंदर "ढेर"()।

a=ggplot(df,aes(x = Time,y = Acres, fill=WUClass))+ 
        geom_area(position = 'stack' ) 
a +geom_line(position = 'stack' ) 

... और सब ठीक है।

संबंधित मुद्दे