Using ggplot2
ggthemes a ggplot2 extensionYou can globally set a theme with the theme_set() function:
The function theme() is used to control non-data parts of the graph including:
There is a specific function to modify each of these three elements :
element_line() to modify the line elements of the themeelement_text() to modify the text elementselement_rect() to change the appearance of the rectangle elementselement_blank() to draw nothing and assign no spaceNote: rel() is used to specify sizes relative to the parent, margins() is used to specify the margins of elements.
p3 <- p2 +
theme(
### move and modify legend
legend.title = element_blank(), #<<
legend.position = "top", #<<
legend.key = element_rect(fill = "lightskyblue1", color = "lightskyblue1"), #<<
legend.background = element_rect( fill = "lightskyblue1",color = "pink", size = 0.5,linetype = "longdash") #<<
)Can be modified in several ways: - labs(), xlab(), ylab(), ggtitle() - You can also set axis and legend labels in the individual scales (using the first argument, the name) e.g. scale_x_continuous() .
We can save the results of a plot to a file (as an image) using the ggsave() function:
bill length versus bill width from the penguins and color by species.