Legend Labeling

123 views
Skip to first unread message

Ed

unread,
Jun 9, 2009, 10:47:12 AM6/9/09
to ggplot2
Hi,

usually ggplot automatically gives the legend the name of the colours-
variable in aes(x,y, colours=variable).

Is there a function to give the legend an independent lable ?

Greetz,

Ed

David Kahle

unread,
Jun 9, 2009, 10:51:59 AM6/9/09
to Ed, ggplot2
Take a look at scale_colour_discrete :

a <- 1:50; b <- 1:50; c <- factor(rep(1:2, each = 25))
qplot(a, b, geom = 'point', colour = c) + 
  scale_colour_discrete('Title', labels = c('One','Two'))

best
david.

Ed

unread,
Jun 9, 2009, 12:02:46 PM6/9/09
to ggplot2
Hey thank you very much man, it works !

Another, similar problem is, how to independently name the x-or-y-
axises ? There are functions scale_x_discrete(...) or
scale_x_continuous(...), but I recently write functions in order to
easily create diagrams ... and I need a function, which helps naming
the axis, regardless they have discrete or continuous scales.

Is there such an overall-function ?

Thanks in advance,

Ed

David Kahle

unread,
Jun 9, 2009, 12:07:11 PM6/9/09
to Ed, ggplot2
Try xlab and ylab :

a <- factor(1:50)
b <- factor(1:50)
c <- factor(rep(1:2, each = 25))
qplot(a, b, geom = 'point', colour = c) + 
  scale_colour_discrete('Title', labels = c('One','Two')) +
  xlab('x axis') + ylab('y axis')

Cheers
david

Ed

unread,
Jun 9, 2009, 12:13:11 PM6/9/09
to ggplot2
Thanks a lot for the quick answer ! I feel pretty stupid now :-D,
think I need a coffee :-D.

Have a nice day !

Ed

Ed

unread,
Jun 11, 2009, 11:26:11 AM6/11/09
to ggplot2
hey, it's me again :-)

Sometimes ylab("...") or scale_colour_discrete('Title') don't work,
whereas xlab("..") always works. Anybody knows what could be the
reason for that ?

Thanks in advance and kind regards,

Ed
Reply all
Reply to author
Forward
0 new messages