Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot font size for different elements

Tags:

r

ggplot2

I know that after I create a ggplot graph I can use theme_get() to return detail of all the theme elements. This has been very helpful in figuring out things like strip.text.x and the like. But I have two things I can't figure out:

1) In the following ggplot graphic, what is the name of the theme item representing the phrase "Percent of wood chucked by the woodchuck" as I want to resize it to a larger font:

enter image description here

2) How do I reformat the y axis labels to read 10%, 20, ... instead of .1, .2, ...

like image 583
JD Long Avatar asked Nov 11 '11 17:11

JD Long


2 Answers

For 1), it is $axis.title.y

p + theme(axis.title.x = element_text(size = 25))

where p is an existing ggplot object.

I don't know about 2) off hand.

like image 55
Gavin Simpson Avatar answered Oct 08 '22 02:10

Gavin Simpson


For (2) what you want is to use a formatter:

dat <- data.frame(x=1:10,y=1:10)

#For ggplot2 0.8.9    
ggplot(dat,aes(x = x/10,y=y/10)) + 
    geom_point() +
    scale_x_continuous(formatter = "percent")

#For ggplot2 0.9.0    
ggplot(dat,aes(x = x/10,y=y/10)) + 
    geom_point() +
    scale_x_continuous(labels = percent_format())

enter image description here

like image 31
joran Avatar answered Oct 08 '22 04:10

joran