背景介绍
ggplot中有时候需要做一些分面图,那么对于这些分面的字体、颜色、背景是怎么修改的呢?今天我们来看一下!
软件介绍
[软件名称]:R(4.1.2)
[软件名称]:RStudio(1.4.1106)
教程介绍
1.加载需要的包,我一般喜欢直接加载tidyverse
library(tidyverse)
2.首先我们使用R语言内置的数据集绘制一个图
ggplot(iris,aes(Sepal.Length,Sepal.Width))+ geom_point(aes(size=Petal.Length,color=Petal.Width))+ facet_grid(.~Species)
3.然后使用windowsFonts提取系统字体Times New Roman,使用scale_color_gradient修改颜色范围
windowsFonts(A=windowsFont("Times New Roman")) ggplot(iris,aes(Sepal.Length,Sepal.Width))+ geom_point(aes(size=Petal.Length,color=Petal.Width))+ facet_grid(.~Species)+ scale_color_gradient(low = "blue",high = "red")+ theme(text=element_text("A",size=