English 中文(简体)
ggplot2 - Themes
  • 时间:2024-12-22

ggplot2 - Themes


Previous Page Next Page  

In this chapter, we will focus on using customized theme which is used for changing the look and feel of workspace. We will use “ggthemes” package to understand the concept of theme management in workspace of R.

Let us implement following steps to use the required theme within mentioned dataset.

GGTHEMES

Install “ggthemes” package with the required package in R workspace.


> install.packages("ggthemes")
> Library(ggthemes)
GGTHEMES

Implement new theme to generate legends of manufacturers with year of production and displacement.


> pbrary(ggthemes)
> ggplot(mpg, aes(year, displ, color=factor(manufacturer)))+
+ geom_point()+ggtitle("This plot looks a lot different from the default")+
+ theme_economist()+scale_colour_economist()
Implement New Theme

It can be observed that the default size of the tick text, legends and other elements are pttle small with previous theme management. It is incredibly easy to change the size of all the text elements at once. This can be done on creating a custom theme which we can observe in below step that the sizes of all the elements are relative (rel()) to the base_size.


> theme_set(theme_gray(base_size = 30))
> ggplot(mpg, aes(x=year, y=class))+geom_point(color="red")
Implement New Theme Advertisements