Im trying to make a combine a graph to three boxplots in R using ggarange. But then it gives me the error: Warning: Cannot convert object of class list into a grob.Warning: Cannot convert object of class list into a grob.Warning: Cannot convert object of class list into a grob. I tried several things from Stackoverflow but nothing seems to work for my code.
I use the following code to make the boxplots:
clr <- hcl.colors(length(unique(df6$Q8)), alpha=.5)
blr <- hcl.colors(length(unique(df6$Q8)), alpha=1)
A <- boxplot(AI ~ Q8,data=df6,
xlab="walking ability", ylab="% active", col=clr, border=blr)
corr <- with(df6, cor.test(AI, Q8))[c('estimate', 'conf.int')]
legend('topleft',
legend=bquote(rho ==.(signif(corr[[1]], 2))~'['*.(signif(corr[[2]][1], 2))*','~.(signif(corr[[2]][2], 2))*']'),
bty='n')
clr <- hcl.colors(length(unique(df6$Q8)), alpha=.5)
blr <- hcl.colors(length(unique(df6$Q8)), alpha=1)
B <- boxplot(activity ~ Q8,data=df6,
xlab="Walking ability", ylab="% active", col=clr, border=blr)
corr <- with(df6, cor.test(activity, Q8))[c('estimate', 'conf.int')]
legend('topleft',
legend=bquote(rho ==.(signif(corr[[1]], 2))~'['*.(signif(corr[[2]][1], 2))*','~.(signif(corr[[2]][2], 2))*']'),
bty='n')
clr <- hcl.colors(length(unique(df6$Q8)), alpha=.5)
blr <- hcl.colors(length(unique(df6$Q8)), alpha=1)
C <- boxplot(ZIM_SD ~ Q8,data=df6,
xlab="Walking ability", ylab="Zero inflated model", col=clr, border=blr)
corr <- with(df6, cor.test(ZIM_SD, Q8))[c('estimate', 'conf.int')]
legend('topleft',
legend=bquote(rho ==.(signif(corr[[1]], 2))~'['*.(signif(corr[[2]][1], 2))*','~.(signif(corr[[2]][2], 2))*']'),
bty='n')
Then I use this code to combine the graphs (this leads to the error).
ggarrange(A, # First row with line plot
# Second row with box and dot plots
ggarrange(B, C, ncol = 2, labels = c("", "")),
nrow = 2,
labels = "" # Label of the line plot
)