Graphics Reference
In-Depth Information
appearance of the x-axis label and plot.title controls the appearance of the title text ( Fig-
ure 9-3 , left):
library(gcookbook) # For the data set
# Base plot
p <- ggplot(heightweight, aes(x = ageYear, y = heightIn)) + geom_point()
# Controlling appearance of theme items
p + theme(axis.title.x = element_text(size = 16 , lineheight = .9 , family = "Times" ,
face = "bold.italic" , colour = "red" ))
p + ggtitle( "Age and Height\nof Schoolchildren" ) +
theme(plot.title = element_text(size = rel( 1.5 ), lineheight = .9 , family = "Times" ,
face = "bold.italic" , colour = "red" ))
# rel(1.5) means that the font will be 1.5 times the base font size of the theme.
# For theme elements, font size is in points.
To set the appearance of text geoms (text that's in the plot itself, with geom_text() or annot-
ate() ), set the text properties. For example ( Figure 9-3 , right):
p + annotate( "text" , x = 15 , y = 53 , label = "Some text" , size = 7 , family = "Times" ,
fontface = "bold.italic" , colour = "red" )
p + geom_text(aes(label = weightLb), size = 4 , family = "Times" , colour = "red" )
# For text geoms, font size is in mm
Search WWH ::




Custom Search