[R] ggplot2: changing axis labels in ggplot()

James D Forester jdforest at uchicago.edu
Tue Nov 13 23:30:25 CET 2007


Hi all,

For various reasons, I need to use ggplot instead of qplot for a complex
figure. Everything is working fine, except I cannot figure out how to rename
the axis labels in ggplot. I have pasted a simple example below. Any ideas
on what I am doing wrong?

Thanks for your help.

James



library(ggplot2)
##create data
mydat<-data.frame("site"=sample(c(0,1),100,replace=T),"response"=rnorm(100,5,2))
mydat$predictor<-mydat$response*1.5+rnorm(100)

##qplot works fine
qp<-qplot(predictor,response,data=mydat,xlab="Predictor
Variable",ylab="Response Variable")

##However, trying this with ggplot, I cannot change the axis labels
p<-ggplot(data=mydat,aes(shape=factor(site),x=predictor,y=response))
p$xlabel="Predictor Variable"
p$ylabel="Response Variable"
p+geom_point()
-- 
View this message in context: http://www.nabble.com/ggplot2%3A-changing-axis-labels-in-ggplot%28%29-tf4801014.html#a13736149
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list