Adjusting fontsize on plots

2,336 views
Skip to first unread message

bhive

unread,
Mar 12, 2010, 9:43:55 AM3/12/10
to ggplot2
Hello,

I've been trying to use ggplot2 to plot means and standard errors. I
increased the size of the png outputs to make them crisp at higher
resolution, but this makes the font tiny on the axes and axes labels.
I looked up how to do it, but I can't even get the examples to work.

From http://had.co.nz/ggplot2/book.pdf :

qplot(mpg, wt, data=mtcars, facets = . ~ cyl)
grid.gedit("label", gp=gpar(fontsize=14, col="red"))

I get:

Error in editDLfromGPath(gPath, specs, strict, grep, global,
redraw) :
'gPath' (label) not found

Is there a different way to do it that I'm unaware of. Have things
changed in a newer version that the documentation hasn't caught up
with yet?

Thanks,

Brandon

Brandon Hurr

unread,
Mar 12, 2010, 9:53:07 AM3/12/10
to ggplot2
Here is my session info if it helps at all. 

R version 2.10.1 (2009-12-14) 
x86_64-apple-darwin9.8.0 

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets 
[7] methods   base     

other attached packages:
[1] ggplot2_0.8.6 digest_0.4.2  reshape_0.8.3 plyr_0.1.9   
[5] proto_0.3-8  


--
You received this message because you are subscribed to the ggplot2 mailing list.
To post to this group, send email to ggp...@googlegroups.com
To unsubscribe from this group, send email to
ggplot2+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2

hadley wickham

unread,
Mar 12, 2010, 9:57:16 AM3/12/10
to bhive, ggplot2
Hi Brandon,

I didn't realise that copy of the book was still up on the web - it's
very out of date.

You can probably fix the problem using
theme_set(theme_grey(fontsize)), but that shouldn't be necessary - you
should be adjusting the png dpi not the overall size. It's difficult
to know what's going wrong without a reproducible example.

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Dennis Murphy

unread,
Mar 12, 2010, 10:15:24 AM3/12/10
to bhive, ggplot2
Hi:


Without resorting to grid, you can get increased label size and new colors
through opts(). With your example,

qplot(mpg, wt, data=mtcars, facets = . ~ cyl) +
  opts(axis.title.x = theme_text(size = 14, colour = 'red')) +
  opts(axis.title.y = theme_text(size = 14, colour = 'red', angle = 90))

gets what I think you want from the graph.

My question: why does one need angle = 90 for the y-axis label?
Try this with angle = 90 and without it to see what I mean. Feature or ...?

HTH,
Dennis

Brandon Hurr

unread,
Mar 12, 2010, 10:28:21 AM3/12/10
to hadley wickham, ggplot2
Hadley,

Google knows and sees all. When I searched for font size in ggplot2 that's one of the only hits I got that seemed relevant. Too bad it was so badly out of date. 

I was adjusting the width and height of the output without adjusting the resolution/DPI. With the following I get good looking output. 

png(filename=path.expand(paste("~/desktop/results/", fp, sep="")) , type="quartz", width = 1200, height = 1200, res=200) 

Dennis, 

I have an opt() line in my function, and adjusting the text in there works well so thanks for your advice. 

Thanks, 

Brandon

P.S. I should have figured it was something simple, and sorry about not supplying a slimmed down example. It's been a while since my little program has been simple and my brain hurts from a busy week. 
Reply all
Reply to author
Forward
0 new messages