ggplot2 - 主题



在本章中,我们将重点介绍使用自定义主题,该主题用于更改工作区的观感。我们将使用“ggthemes”包来理解 R 工作区中的主题管理概念。

让我们执行以下步骤,在提到的数据集中使用所需的主题。

GGTHEMES

在 R 工作区中使用所需的包安装“ggthemes”包。

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

实施新主题来生成制造商图例及其生产年份和排量。

> library(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

可以观察到,使用以前的主题管理后,刻度线、图例和其他元素的默认大小都比较小。轻松更改所有文本元素的大小。这可以通过创建一个自定义主题来实现,在以下步骤中可以看到,所有元素的大小都与 base_size 相对 (rel())。

> theme_set(theme_gray(base_size = 30))
> ggplot(mpg, aes(x=year, y=class))+geom_point(color="red")
Implement New Theme
广告
© . All rights reserved.