On 11/5/2012 12:05 PM, Thiago V. dos Santos wrote:
> Dear plotter colleagues,
>
> I am really novice in ggplot2 and I'm struggling to improve a graphic.
> Here is the code I use to produce my plot:
>
> p <- ggplot(a, aes(x=year, y=value, fill=as.factor(class)))
> p + geom_bar(position="fill", width=0.5) +
> labs(x= 'Year', y= 'Proportion') +
> scale_colour_brewer(palette=5, name='Classes') +
> theme(legend.title=element_text(face = "italic"))
>
> and it yields this graphic:
>
http://imageshack.us/content_round.php?page=done&l=img194/1445/outrb.png
Since this is not reproducible (we don't have a), some of the following
are just guesses. However, the image was helpful.
> However, there are a few things that I would like to improve. For example:
>
> 1) Most important: I have 100 years on "x" axis, which is a lot of data,
> and therefore they are squeezed. How can I "stretch" plot dimensions in
> order to display all numbers in a legible way?
year is probably discrete (character or factor) rather than continuous
(numeric). Convert it to numeric and the continuous scale will not make
every value into a tick. If you really need it as a discrete variable,
the breaks option to scale_x_discrete allows you to specify which values
are shown.
> 2) How can I mantain this scale and change only the legend title?
> Options *scale_colour_brewer(palette=5,
> name='Classes') + theme(legend.title=element_text(face = "italic"))* don't
> make any effect.
The aesthetic that corresponds to the legend you see is fill, not
colour. So use scale_fill_brewer, not scale_colour_brewer.
> 3) How can I get rid of that grey bars on the top of the plot?
That is the background of the plot. If you don't want it to be gray, you
can just change that in the theme, or use theme_bw(). If you don't want
the space there at all, then you can set the y axis limits to exactly 0
and 1. You may also need to set expand to c(0,0); I don't recall.
> Any suggestion?
>
> Many thanks in advance,
> Thiago.
>
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University