JD Long
JD Long

Reputation: 60746

ggplot font size for different elements

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, ...

Upvotes: 10

Views: 3771

Answers (2)

Gavin Simpson
Gavin Simpson

Reputation: 174813

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.

Upvotes: 8

joran
joran

Reputation: 173577

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

Upvotes: 4

Related Questions