[R] ggplot2 font size problem

dhzdhz myjunkbox at gmail.com
Mon Aug 11 20:24:52 CEST 2008


x=c("abcdefghijklmn", "opqrstuvwxyz")
y=c(1, 2)
df=data.frame(name=x, value=y)
p=ggplot(df, aes(name, value))+geom_point()
grid.gedit(gPath("xaxis"), gp=gpar(fontsize=8))
print(p)

It doesn't work. I have to print(p) before I change the font size.
Furthermore, this change will be overwritten by default if I print(p) again.
And the worst is that it works very ugly in y axis.

Instead

p=ggplot(df, aes(name, value))+geom_point()

I used 

p=ggplot(df, aes(value, name))+geom_point()
grid.gedit(gPath("yaxis"), gp=gpar(fontsize=8))

The whole label and ticks are moved left due to smaller fonts. However, the
figure doesn't. And now the ticks and labels are detached from the axis.

Can I change the default setting?

Thanks

This only works AFTER I plot out the figure. And if I replot again, the
fontsize is back to default setting.



hadley wrote:
> 
> Hi dhzdhz,
> 
> There's currently no particularly easy way to do this.  It is possible
> to use grid to edit these labels directly (see
> http://had.co.nz/ggplot2/book/grid.pdf), but the next version of
> ggplot2 will have a more convenient theming system that will make it
> much easier to make these sorts of changes.
> 
> Hadley
> 
> On Mon, Aug 11, 2008 at 10:55 AM, dhzdhz <myjunkbox at gmail.com> wrote:
>>
>> How do I change the font size of the label in ggplot. For example
>>
>> x=c("abcdefghijklmn", "opqrstuvwxyz")
>> y=c(1, 2)
>> df=data.frame(name=x, value=y)
>>
>> p=ggplot(df, aes(name, y))+geom_point()
>>
>> Now the name of "abcdefghijklmn" and "opqrstuvwxyz" are too long. How can
>> I
>> change the font size of them. And can I also change the orientation of
>> them?
>>
>> thanks
>> --
>> View this message in context:
>> http://www.nabble.com/ggplot2-font-size-problem-tp18928577p18928577.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 
> 
> -- 
> http://had.co.nz/
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/ggplot2-font-size-problem-tp18928577p18930611.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list