2012-05-03 6 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으로 보내지 않아도됩니다. 한 가지 이점은 ggplotdata.frame과 직접 작동한다는 것입니다.

xlab()ylab()으로 레이블을 설정하거나 scale_*.* 호출의 일부로 지정할 수 있습니다. 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)") 
를 사용하고 (당신이 저울의 다른 측면을 변경하지 않는 경우 편리)

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

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)") 
단지 지정하는 또 다른 방법은 레이블

위의 그림에 대한 엔틱 한 그림.