2012-05-03 26 views
94

このグラフのxとyのラベルを変更するにはどうすればよいですか?ggplot2でx軸とy軸のラベルを追加する

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があるので

あなたの例では再現できない(Sleuth2ex1221ありませんので、私はそれはあなたが何を意味するのかを推測します)。また、列を引き出してggplotに送信する必要はありません(また、そうしないでください)。 1つの利点はggplotdata.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)") 
を使用しています

これはid上のものへの象徴的な数字。

関連する問題