2012-05-03 18 views
94

में x और y अक्ष लेबल जोड़ना कृपया इस ग्राफ पर x और y लेबल कैसे बदलें?ggplot2

library(Sleuth2) 
library(ggplot2) 
discharge<-ex1221new$Discharge 
area<-ex1221new$Area 
nitrogen<-ex1221new$NO3 
p <- ggplot(ex1221new, aes(discharge, area), main="Point") 
p + geom_point(aes(size= nitrogen)) + 
    scale_area() + 
    opts(title = expression("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)"), 
     subtitle="n=41") 

उत्तर

148

[नोट: ggplot वाक्य रचना को आधुनिक बनाने के संपादित]

आपका उदाहरण के बाद से कोई ex1221new है प्रतिलिपि प्रस्तुत करने योग्य नहीं है (वहाँ है Sleuth2 में एक ex1221, इसलिए मुझे लगता है कि यह है कि आप क्या मतलब है)। साथ ही, आपको ggplot पर भेजने के लिए स्तंभों को खींचने की आवश्यकता नहीं है (और नहीं)। एक फायदा यह है कि ggplot सीधे data.frame एस के साथ काम करता है।

आप xlab() और ylab() के साथ लेबल सेट कर सकते हैं, या इसे scale_*.* कॉल का हिस्सा बना सकते हैं।

library("Sleuth2") 
library("ggplot2") 
ggplot(ex1221, aes(Discharge, Area)) + 
    geom_point(aes(size=NO3)) + 
    scale_size_area() + 
    xlab("My x label") + 
    ylab("My y label") + 
    ggtitle("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)") 

enter image description here

ggplot(ex1221, aes(Discharge, Area)) + 
    geom_point(aes(size=NO3)) + 
    scale_size_area("Nitrogen") + 
    scale_x_continuous("My x label") + 
    scale_y_continuous("My y label") + 
    ggtitle("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)") 

enter image description here

सिर्फ निर्दिष्ट करने के लिए एक वैकल्पिक तरीका (काम करता है, तो आप तराजू के किसी भी अन्य पहलुओं नहीं बदल रहे हैं) लेबल labs समारोह

ggplot(ex1221, aes(Discharge, Area)) + 
    geom_point(aes(size=NO3)) + 
    scale_size_area() + 
    labs(size= "Nitrogen", 
     x = "My x label", 
     y = "My y label", 
     title = "Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)") 
उपयोग कर रहा है

जो एक आईडी देता है उपर्युक्त के लिए एकमात्र आंकड़ा।