我正在尝试使用https://gist.github.com/adamwespiser/3077780中的以下代码:
theme_publish <- function(base_size = 12) {
structure(list(
axis.line = theme_blank(),
axis.text.x = theme_text(size = base_size * 0.8 , lineheight = 0.9, vjust = 1),
axis.text.y = theme_text(size = base_size * 0.8, lineheight = 0.9, hjust = 1),
axis.ticks = theme_segment(colour = "black", size = 0.2),
axis.title.x = theme_text(size = base_size, vjust = 1),
axis.title.y = theme_text(size = base_size, angle = 90, vjust = 0.5),
axis.ticks.length = unit(0.3, "lines"),
axis.ticks.margin = unit(0.5, "lines"),
legend.background = theme_rect(colour=NA),
legend.key = theme_rect(colour = "grey80"),
legend.key.size = unit(1.2, "lines"),
legend.text = theme_text(size = base_size * 0.8,family = "sans"),
legend.title = theme_text(size = base_size * 0.8, face = "bold", hjust = 0),
legend.position = "right",
panel.background = theme_rect(fill = "white", colour = NA),
panel.border = theme_rect(fill = NA, colour="grey50"),
panel.grid.major = theme_blank(),
panel.grid.minor = theme_blank(),
panel.margin = unit(0.25, "lines"),
strip.background = theme_rect(fill = "grey80", colour = "grey50"),
strip.text.x = theme_text(size = base_size * 0.8),
strip.text.y = theme_text(size = base_size * 0.8, angle = -90),
plot.background = theme_rect(colour = NA),
plot.title = theme_text(size = base_size * 1.2),
plot.margin = unit(c(1, 1, 0.5, 0.5), "lines")
), class = "options")
}
我正在尝试使用此功能,如下所示:
ggplot(mtcars,aes(mpg,hp,size=wt))+geom_point()+theme_publish()
但是,它不起作用,并且存在如下错误:
Error: Use 'element_text' instead. (Defunct; last used in version 0.9.1)
我可以一次更正所有内容还是需要将每一行更改为新的代码格式?谢谢你的帮助。
编辑: 根据@Metrics的评论,我试图用'element_'替换所有'theme_',将theme_segment更改为element_line,加载网格包,将类更改为'theme'。修改后的功能是:
theme_publish <- function(base_size = 12) {
structure(list(
axis.line = element_blank(),
axis.text.x = element_text(size = base_size * 0.8 , lineheight = 0.9, vjust = 1),
axis.text.y = element_text(size = base_size * 0.8, lineheight = 0.9, hjust = 1),
axis.ticks = element_line(colour = "black", size = 0.2),
axis.title.x = element_text(size = base_size, vjust = 1),
axis.title.y = element_text(size = base_size, angle = 90, vjust = 0.5),
axis.ticks.length = unit(0.3, "lines"),
axis.ticks.margin = unit(0.5, "lines"),
legend.background = element_rect(colour=NA),
legend.key = element_rect(colour = "grey80"),
legend.key.size = unit(1.2, "lines"),
legend.text = element_text(size = base_size * 0.8,family = "sans"),
legend.title = element_text(size = base_size * 0.8, face = "bold", hjust = 0),
legend.position = "right",
panel.background = element_rect(fill = "white", colour = NA),
panel.border = element_rect(fill = NA, colour="grey50"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.margin = unit(0.25, "lines"),
strip.background = element_rect(fill = "grey80", colour = "grey50"),
strip.text.x = element_text(size = base_size * 0.8),
strip.text.y = element_text(size = base_size * 0.8, angle = -90),
plot.background = element_rect(colour = NA),
plot.title = element_text(size = base_size * 1.2),
plot.margin = unit(c(1, 1, 0.5, 0.5), "lines")
), class = "theme")
}
但现在我收到了错误:
Error in if (attr(newtheme, "complete")) return(newtheme) : argument is of length zero
我无法弄清楚它来自哪条线。