R语言 DescTools一次显示多个图形

92dk7w1h  于 2023-05-20  发布在  其他
关注(0)|答案(2)|浏览(201)

我曾尝试使用DescTools软件包一次显示多个图形,但我找不到绘图对象!!!

library("ggplot2")    
p1<-plot(Desc(dist ~ speed, data=cars), smooth="none")
p2<-plot(Desc(dist ~ speed, data=cars), smooth="exp")
p3<-plot(Desc(dist ~ speed, data=cars), smooth="lin")
p4<-plot(Desc(dist ~ speed, data=cars), smooth="spline")
p5<-plot(Desc(dist ~ speed, data=cars), smooth="loess")

plot_list <- list(p1, p2, p3, p4, p5) 

library("gridExtra") 
do.call("grid.arrange", c(plot_list, ncol = 3))

library(patchwork)
p1+p2 / (p3 + p4 + p5)

任何想法来实现它?

bogh5gae

bogh5gae1#

使用ggplot可以更容易地将图保存为对象,例如。

library(ggplot2)    

smo_func <- function(smooth_method) {
  ggplot(cars, aes(x = speed, y = dist)) +
  geom_point() + 
  geom_smooth(method = smooth_method) + 
  labs(title  = smooth_method)
}
  
  
p1 <- smo_func(smooth_method = NULL)
p2 <- smo_func(smooth_method = "lm")
p3 <- smo_func(smooth_method = "gam")

library(patchwork)
p1 / (p2  + p3)

lhcgjxsq

lhcgjxsq2#

DescTools使用基本R图形。所以用这个:

par(mfrow=c(2,3))

p1<-plot(Desc(dist ~ speed, data=cars), smooth="none")
p2<-plot(Desc(dist ~ speed, data=cars), smooth="exp")
p3<-plot(Desc(dist ~ speed, data=cars), smooth="lm")
p5<-plot(Desc(dist ~ speed, data=cars), smooth="spline")
p5<-plot(Desc(dist ~ speed, data=cars), smooth="loess")

相关问题