If you look at the code of theme_light() you'll see it calls theme_grey() and theme().function (base_size = 11, base_family = "", base_line_size = base_size/22, base_rect_size = base_size/22) { half_line <- base_size/2 theme_grey(base_size = base_size, base_family = base_family, base_line_size = base_line_size, base_rect_size = base_rect_size) %+replace% theme(panel.background = element_rect(fill = "white", colour = NA), panel.border = element_rect(fill = NA, colour = "grey70", size = rel(1)), panel.grid = element_line(colour = "grey87"), panel.grid.major = element_line(size = rel(0.5)), panel.grid.minor = element_line(size = rel(0.25)), axis.ticks = element_line(colour = "grey70", size = rel(0.5)), legend.key = element_rect(fill = "white", colour = NA), strip.background = element_rect(fill = "grey70", colour = NA), strip.text = element_text(colour = "white", size = rel(0.8), margin = margin(0.8 * half_line, 0.8 * half_line, 0.8 * half_line, 0.8 * half_line)), complete = TRUE)}现在在 theme_grey()中的某处,您将找到以下行:Now somewhere in theme_grey() you'll find the following line:plot.title = element_text(size = rel(1.2), hjust = 0因此,当首先调用 theme(plot.title = element_text(hjust = 0.5))时,它将被 theme_light()覆盖.So when call theme(plot.title = element_text(hjust = 0.5)) first it will be overwritten by theme_light(). 在重复输入ggplot() + geom_something() + theme(plot.title = element_text(hjust = 0.5)) + theme_light()您可以定义自己的主题以保存一些输入内容you might define your own theme to save some typingtheme_WoeIs <- function(base_size = 11, base_family = "", base_line_size = base_size / 22, base_rect_size = base_size / 22, ...) { half_line <- base_size / 2 theme_grey( base_size = base_size, base_family = base_family, base_line_size = base_line_size, base_rect_size = base_rect_size ) %+replace% theme( panel.background = element_rect(fill = "white", colour = NA), panel.border = element_rect( fill = NA, colour = "grey70", size = rel(1) ), panel.grid = element_line(colour = "grey87"), panel.grid.major = element_line(size = rel(0.5)), panel.grid.minor = element_line(size = rel(0.25)), axis.ticks = element_line(colour = "grey70", size = rel(0.5)), legend.key = element_rect(fill = "white", colour = NA), strip.background = element_rect(fill = "grey70", colour = NA), strip.text = element_text( colour = "white", size = rel(0.8), margin = margin(0.8 * half_line, 0.8 * half_line, 0.8 * half_line, 0.8 * half_line) ), complete = TRUE, plot.title = element_text(hjust = 0.5), # here is your part ... # this is new as well ) }让我们尝试一下ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) + ggtitle("Flowers") + theme_WoeIs() 这篇关于是否可以使用"theme_light()"与“主题"一起在ggplot命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 13:26