tags:

views:

68

answers:

1

I am working on finishing up a graph generated using ggplot2 like so...

ggplot(timeSeries, aes(x=Date, y=Unique.Visitors, colour=Revenue)) 
+ geom_point() + stat_smooth() + scale_y_continuous(formatter=comma)

I have attached the result and you can see the numeric values in the legend for Revenue do not have a comma. How can I add a comma to those values? I was able to use scale_y_continuous for the axis, can that be used for the legend also?

alt text

+2  A: 

Yep - just a matter of getting the right scale_colour_ layer figured out. Try:

ggplot(timeSeries, aes(x = Date, y = Unique.Visitors, colour = Revenue)) +
    geom_point() +
    stat_smooth() +
    scale_y_continuous(formatter = comma) +
    scale_colour_continuous(formatter = comma)

I personally would also move my the colour mapping to the geom_point layer, so that it doesn't give you that odd line behind the dot in the legend:

ggplot(timeSeries, aes(x = Date, y = Unique.Visitors)) +
    geom_point(aes(colour = Revenue)) +
    stat_smooth() +
    scale_y_continuous(formatter = comma) +
    scale_colour_continuous(formatter = comma)
Matt Parker
That was good. thanks Matt.
analyticsPierce