2012-12-18 20 views
13
heights1=c(5,5,4.5,4,4,4,4.5,2,4,4) 

opar <- par(lwd = 0.3) 

barplot(heights1,xlim=c(0,3), ylim=c(0,5), width=0.1, 
main="Langauges(Verbal & Non-verbal)", 
names.arg=c("Spanish", "Speak" , "English","Speak", "Hindi", 
"Speak", "Arabic", "Speak", "Body Lang", "Speak"), ylab="Skill level ", 
xlab="Language starting with mostly used", col=c("darkblue","red"), 
cex.names=0.7,space=c(2,0,2,0,2,0,2,0,2,0)) 

legend("top", c("darkblue","red"), c("reading/Writing", "Speaking") ); 

ब्लू "पढ़ने/लिखने" के लिए है और लाल "बोलने" के लिए है। मैं किंवदंती में सुधार कैसे करूं? (मैं barplot समारोह के अंदर कथा को परिभाषित नहीं करना चाहती)बारप्लॉट में किंवदंतियों ठीक से दिखाई नहीं दे रहे हैं

enter image description here

+0

बस आपकी समस्या clarify- है कि कथा रंगों में से प्रत्येक के लिए बॉक्स नहीं है? –

उत्तर

18

आप अपने रंग के लिए fill तर्क का उपयोग कर सकते हैं। डेविड रॉबिन्सन के जवाब के साथ, मैं इस मामले में शीर्ष दाएं भाग में किंवदंती रखने का भी सुझाव दूंगा।

legend("topright", 
     legend = c("reading/Writing", "Speaking"), 
     fill = c("darkblue", "red")) 

enter image description here


अपने अन्य प्रश्न के कुछ को देखते हुए, आप भी अंकन से पहले एक और अधिक उपयुक्त रूप में अपने डेटा प्राप्त करने के लिए कुछ समय खर्च करना चाहते हैं हो सकता है।

heights1 = c(5, 5, 4.5, 4, 4, 4, 4.5, 2, 4, 4) # Your data 
  • यहाँ उचित dimnames

    mydata <- matrix(heights1, ncol = 2, byrow = TRUE, 
           dimnames = list(c("Spanish", "English", "Hindi", 
                "Arabic", "Body Lang"), 
               c("Reading/Writing", "Speaking"))) 
    mydata # Much more meaningful to look at than a simple vector 
    #   Reading/Writing Speaking 
    # Spanish    5.0  5 
    # English    4.5  4 
    # Hindi     4.0  4 
    # Arabic    4.5  2 
    # Body Lang    4.0  4 
    
  • के साथ एक matrix के रूप में अपने डेटा है अपने रंग को परिभाषित करें (:

    1. यहाँ अपने डेटा है:

      यहाँ एक उदाहरण है वैकल्पिक, लेकिन उपयोगी अगर वाई कहां समूह प्रति सलाखों के सिर्फ एक जोड़ी)

      colors <- c("darkblue", "red") # Define the colors you're using 
      
    2. प्लॉट अपने डेटा शीर्ष पर अतिरिक्त स्थान का एक छोटा सा जोड़ने और अपने कुल्हाड़ियों दबाने की तुलना में अधिक के साथ काम कर रहे हैं। सुनिश्चित नहीं हैं कि तुम क्यों इस स्तर पर कथा शामिल नहीं करना चाहते हैं, लेकिन यह आसानी से निम्नलिखित तर्क जोड़कर किया जा सकता है: legend.text = TRUE, args.legend = list(x = "topright", bty = "n")

      barplot(t(mydata), beside = TRUE, col = colors, 
           ylim = c(0, 6), axes = FALSE, 
           xlab = "Language starting with mostly used", 
           main = "Languages (Verbal & Non-verbal)") 
      
    3. अपने y- अक्ष reintroduce करने और अपने कथा जोड़ने

      axis(2, at = 0:5, labels = 0:5) 
      legend("topright", colnames(mydata), fill = colors, bty = "n") 
      

      enter image description here

  • 3

    legend("topright", c("reading/Writing", "Speaking"), col=c("darkblue","red"), lwd=10); 
    

    lwd तर्क करने के लिए अपने legend लाइन बदलें कहते कथा में से प्रत्येक के 10 पिक्सेल मोटाई की तर्ज होना चाहिए संबंधित रंग अपने मामले में "top" के बजाय "topright" का उपयोग करना एक अच्छा विचार है ताकि किंवदंती बार के नीचे दिखाई न दे।

    enter image description here

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

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