使用 autoplot
来自 ggfortify
创建诊断图:
library(ggplot2)
library(ggfortify)
mod <- lm(Petal.Width ~ Petal.Length, data = iris)
autoplot(mod, label.size = 3)
是否可以(轻松)更改轴和绘图标题?我想翻译它们。
最佳答案
函数autoplot.lm
返回一个 S4 对象(类 ggmultiplot,参见 ?`ggmultiplot-class`
)。如果您查看帮助文件,您会看到它们为单个图提供了替换方法。这意味着您可以提取单个图,对其进行修改,然后将其放回原处。例如:
library(ggplot2)
library(ggfortify)
mod <- lm(Petal.Width ~ Petal.Length, data = iris)
g <- autoplot(mod, label.size = 3) # store the ggmultiplot object
# new x and y labels
xLabs <- yLabs <- c("a", "b", "c", "d")
# loop over all plots and modify each individually
for (i in 1:4)
g[i] <- g[i] + xlab(xLabs[i]) + ylab(yLabs[i])
# display the new plot
print(g)
在这里,我只修改了轴标签,但您可以单独更改有关绘图的任何内容(主题、颜色、标题、大小)。
关于r - 更改自动绘图的轴标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44973795/