0

I have tried displaying multiple graphs at once using the DescTools package But I can't find the plot objects!!!

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)  

Any ideas to achieve it?

HerClau
  • 161
  • 2
  • 15

2 Answers2

0

With ggplot it will get easier to save the plot as objects, e.g.

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)  

enter image description here

Julian
  • 6,586
  • 2
  • 9
  • 33
0

DescTools uses base R graphics. So use this:

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")
Andri Signorell
  • 1,279
  • 12
  • 23