> Can anyone tell me how to change the text for the axis labels and
> (especially)
> the legend? Chapter 2 (qplot) of the ggplot book shows that the
> parameters
> to qplot include xlab, ylab, and main, so these can be set if using
> qplot, but I cannot find an explanation for how to do this from
> ggplot. Also, this does not show how to set the text for the title of
> the legend. Chapter 9 ("Polishing your plots for publication") shows
> how to set the attributes of these strings using themes, but I do
> not see how to change the text itself.
The place to look is the scales chapter - the axis/legend title is a
property of the scale and so outside of qplot you need to modify the
corresponding scale.
Hadley
Hi Hadley,
Thank you very much for your help with this. That was
exactly what I needed to know. Also, I would like to thank
David Kahle for helping me with this too.
In case anybody in the future has the same question, here
are the exact commands that I used:
# Create the ggplot object. df is a dataframe
# containing a column named 'dates' that will be
# used for the x-axis.
plot <- ggplot (df, aes(x=dates));
# Set the text for the x-axis. Note that since the data is
# of type Date, one must use scale_x_date. For other data,
# one might use scale_x_discrete or scale_x_continuous.
plot <- plot + scale_x_date("Date");
# Set the text for the y-axis.
plot <- plot + scale_y_continuous("Value");
# Set the text for the legend.
plot <- plot + scale_colour_discrete("Predictive model");
--
Matthew Clegg
matthew...@gmail.com
I should mention that there's a new (but not very well documented)
feature in the latest version. You can do:
plot + labs(x = "Date", y = "Value", colour = "Predictive model")
It saves a bit of typing!
Hadley