Die vorgeschlagenen Lösungen von @ user20650 sind interessant und elegant.
Hier ist eine weniger elegante Lösung basierend auf myautoplot
, eine modifizierte Version von autoplot
. Ich hoffe, es kann dir helfen.
Laden Sie die myautoplot
Funktion here herunter und speichern Sie sie in Ihrem Arbeitsverzeichnis unter dem Namen myautoplot.r
.
Dann verwenden den folgenden Code:
library(ggplot2)
library(ggfortify)
source("myautoplot.r")
mod <- lm(Petal.Width ~ Petal.Length, data = iris)
####
# Define x-labels, y-labels and titles
####
# Residuals vs Fitted Plot
xlab_resfit <- "Xlab ResFit"
ylab_resfit <- "Ylab ResFit"
title_resfit <- "Title ResFit"
# Normal Q-Q Plot
xlab_qqplot <- "Xlab QQ"
ylab_qqplot <- "Ylab QQ"
title_qqplot <- "Title QQ"
# Scale-Location Plot
xlab_scaleloc <- "Xlab S-L"
ylab_scaleloc <- "Ylab S-L"
title_scaleloc <- "Title S-L"
# Cook's distance Plot
xlab_cook <- "Xlab Cook"
ylab_cook <- "Ylab Cook"
title_cook <- "Title Cook"
# Residuals vs Leverage Plot
xlab_reslev <- "Xlab Res-Lev"
ylab_reslev <- "Ylab Res-Lev"
title_reslev <- "Title Res-Lev"
# Cook's dist vs Leverage Plot
xlab_cooklev <- "Xlab Cook-Lev"
ylab_cooklev <- "Ylab Cook-Lev"
title_cooklev <- "Title Cook-Lev"
# Collect axis labels and titles in 3 lists
xlab_list <- list(resfit=xlab_resfit, qqplot=xlab_qqplot,
scaleloc=xlab_scaleloc, cook=xlab_cook, reslev=xlab_reslev,
cooklev=xlab_cooklev)
ylab_list <- list(resfit=ylab_resfit, qqplot=ylab_qqplot,
scaleloc=ylab_scaleloc, cook=ylab_cook, reslev=ylab_reslev,
cooklev=ylab_cooklev)
title_list <- list(resfit=title_resfit, qqplot=title_qqplot,
scaleloc=title_scaleloc, cook=title_cook, reslev=title_reslev,
cooklev=title_cooklev)
# Pass the lists of axis labels and title to myautoplot
myautoplot(mod, which=1:6, xlab=xlab_list,
ylab=ylab_list,
title=title_list)
Dies funktioniert gut für eine einzelne Handlung, aber wie jede Handlung separat erstellt werden muss, wie man sie kombiniert? weder 'grid.arrange' noch' cowplot's 'plot_grid' funktionieren aufgrund der Klasse des 'autoplot'-Objekts. – beetroot
@beetroot; Sie könnten die Figuren, die Etiketten anpassen, durchlaufen. 'm <- mapply (Funktion (w, x, y, z) Autoplot (mod, was = w) + Labs (x = x, y = y, Titel = z), w = 1: 6, x = paste0 ("x", 1: 6), y = paste0 ("y", 1: 6), z = paste0 ("tit", 1: 6)). Es gibt wahrscheinlich einen einfacheren Weg, sie zu kombinieren, aber das scheint zu funktionieren: 'l <- do.call (c, lapply (m, Funktion (x) x @ Plots)); gridExtra :: grid.arrange (grobs = l, ncol = 2) ' – user20650
scheint auch' p [1,1] <- p [1,1] + labs (x = "x-axis label of fig1" , y = "y-Achsenbeschriftung von fig1", title = "Fig1-Plot"), was vielleicht eine andere Route ergibt (p ist der ursprüngliche Autoplot) – user20650