Great :)
> I've got a couple of questions though. I'm generating a stacked
> histogram as follows:
>
> ggplot(pystone, aes(x=ml*16,fill=factor(level))) + geom_bar()
>
> I am able to customize the x and y axis labels:
>
> ggplot(pystone, aes(x=ml*16,fill=factor(level))) + geom_bar() +
> scale_x_log2('bytes referenced') + scale_y_continuous('transactions')
>
> but nothing I can do seems to set the legend label, which is just
> factor(level). I tried various scale_colour_* stuff and labs
> (colour='...') but neither .
You were pretty close: scale_fill_continuous("My label") should do the trick.
> Also, the legend has 1 at the top and 9 at the bottom, whereas the
> graph has 1 at the bottom and 9 at the top; is it possible to reverse
> the legend so it matches the graph?
scale_fill_continuous("My label", breaks = 9:1)
> The tick labels are 2^10, 2^11, 2^12, etc... I'd rather them show up
> as 1K, 2K, etc. since they represent memory use. Is there a way to
> provide some kind of custom formatter function for the tick labels?
You can do something like this:
qplot(mpg, wt, data=mtcars) + scale_x_continuous(formatter=dollar)
The formatter function should take a numeric vector as input and
return an appropriately formatted character vector.
Regards,
Hadley
Oooh, yeah, the log scale would override the formatter.
> I was able to get the labels to appear as desired with:
>
> scale_x_continuous(name='bytes referenced', breaks=2**(10:15),
> formatter=kilobytes)
>
> but the ticks have a linear rather than logarithmic scale, which makes
> the data hard to interpret in my case. I tried with scale_x_discrete
> but no labels at all appeared. Is there a way to get custom labels
> but keep the log scale, somehow, or do I need to rescale my data?
Try this:
breaks <- breaks=2**(10:15)
scale_x_log2(name='bytes referenced', breaks = breaks, labels =
kilobytes(breaks))
> Thanks for the quick help on the other stuff - it works perfectly now.
Great!
Hadley
Did James' answer help you? If not, it's very hard to tell exactly
what is going wrong and suggest how to fix it without a reproducible
example. If you can reproduce it with a built in data set that's the
best, otherwise include a small sample of your data, if possible.