我试图更改stl分解图的facet标签,如下所示:
library(ggplot2)
library(ggfortify)
p <- autoplot(stl(AirPassengers, s.window = 'periodic'), ts.colour = "black", ts.size = 0.2)
p情节来源于ggfortify软件包。我希望将面片标签改为:
c("Original Data", "Seasonal component", "Trend component", "Remainder")我尝试进入ggplot的结构(很多str'ing),并发现以下存储了这些名称:
str(p$layers[[1]]$data$variable)
# Factor w/ 4 levels "Data","seasonal",..: 1 1 1但是,当我改变这个因素的时候。我得到四个空的地块,然后是适当的地块:
p$layers[[1]]$data$variable <- factor(p$layers[[1]]$data$variable,
labels=c("Original series", "Seasonal Component", "Trend component", "Remainder"))

如何更改面标签,而不将这些空的地块放在顶部?
发布于 2015-05-20 16:02:29
一种可能是更改绘图对象的相关组件。
# generate plot data which can be rendered
g <- ggplot_build(p)
# inspect the object and find the relevant element to be changed
# str(g)
# perform desired changes
g$panel$layout$variable <- c("Original Data", "Seasonal component", "Trend component", "Remainder")
# build a grob and 'draw' it
grid.draw(ggplot_gtable(g))

https://stackoverflow.com/questions/30349637
复制相似问题