自动阻止图例被图裁剪 (R)

Automatically Stop Legend from getting Cropped by Plots (R)

我正在使用 R 编程语言。我生成了以下数据:

 credibility_scoree = rnorm(100, 1, 0.3)
 average_recorded_height_in_study = rnorm(100, 17,3)
my_data = data.frame(credibility_scoree, average_recorded_height_in_study )
 my_data$credibility_score = ifelse(my_data$credibility_scoree>1,1,my_data$credibility_scoree)
my_data$credibility_score = my_data$credibility_score  * my_data$credibility_score 
my_data$credibility_scoree = NULL
my_data$study_number <- seq_along(my_data[,1])
my_data$adjusted_weight <- my_data$credibility_score * my_data$average_recorded_height_in_study

然后我尝试使用以下库制作绘图:

library(fitdistrplus)

 fg <- fitdist(my_data$adjusted_weight, "gamma")
 fln <- fitdist(my_data$adjusted_weight, "lnorm")
fg <- fitdist(my_data$adjusted_weight, "gamma")
 fw <- fitdist(my_data$adjusted_weight, "weibull")

 par(mfrow = c(2, 2))
 plot.legend <- c("Weibull", "lognormal", "gamma")

 denscomp(list(fw, fln, fg), legendtext = plot.legend)
qqcomp(list(fw, fln, fg), legendtext = plot.legend)
 cdfcomp(list(fw, fln, fg), legendtext = plot.legend)
 ppcomp(list(fw, fln, fg), legendtext = plot.legend)

如这些图片所示,图例隐藏在图表中。

问题:有没有自动阻止这种情况发生的方法?

谢谢

我真的很抱歉添加 plotstyle = "ggplot 需要添加到每一行......但我认为这可能会帮助你摆脱那些奇怪的传说位置。

library(patchwork)
a <- denscomp(list(fw, fln, fg), legendtext = plot.legend, plotstyle = "ggplot")
b <- qqcomp(list(fw, fln, fg), legendtext = plot.legend, plotstyle = "ggplot")
c <- cdfcomp(list(fw, fln, fg), legendtext = plot.legend, plotstyle = "ggplot")
d <- ppcomp(list(fw, fln, fg), legendtext = plot.legend, plotstyle = "ggplot")

a+b+c+d