1

I am very new to programming, but I managed to get around making faceted scatterplots and marginal box plots for scatter plots using advice in the link below: http://www.lreding.com/nonstandard_deviations/2017/08/19/cowmarg/

My question is how can I make marginal boxplots on my faceted scatterplot?

My code is:

CN<-read.csv("LfFlw.csv")
library(ggplot2)

Simple scatter plot:

ggplot(data=CN, aes(x=PlantOrder, y=CN, colour=Tissue))+geom_point()+facet_wrap(~Population, scales="free_x", nc=2)

Scatterplot black and white:

sc<-ggplot(data=CN, aes(x=PlantOrder, y=CN, shape=Tissue))+geom_point()+facet_wrap(~Population, scales="free_x", nc=2)
sc

Scatter plot with labelled axes:

sc_lab<-sc+labs(x="Individual plants (ordered)", y="Cyanide (ug g^-1 dw)")
sc_lab

Scatter plot with labelled axes and classic theme:

sc_lab_th<-sc_lab+theme_classic()
sc_lab_th

Scatter plot with labelled axes and classic theme with changed shapes:

s<-sc_lab_th+scale_shape_manual(values=c(8,2))
s

Boxplot with facet and white/grey:

y_box <- axis_canvas(s, axis = "y") + geom_boxplot(data = CN, outlier.shape = 1, aes(x = 0, y = CN, fill=Tissue)) + 
  facet_wrap(~Population, scales="free_x", nc=2)+scale_fill_manual(values=c("white", "grey"))
y_box

library(cowplot)

ggdraw(insert_yaxis_grob(s, y_box, position = "left"))

And here I end up with an error:

Error in get_panel(grob) : Plot must contain exactly one panel

aosmith
  • 34,856
  • 9
  • 84
  • 118
Ed1101
  • 11
  • 1
  • Please provide a reproducible example, by either making your dataset available, providing it via the output of `dput()`, or (preferred) making up a simplified dataset that has the same key features as your real one. See also [here.](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Claus Wilke Dec 13 '17 at 04:23

1 Answers1

0

The answer is: You can't. (At least not via the axis_canvas() / insert_yaxis_grob() route. The error message tells you exactly what's going on: The function insert_yaxis_grob() can only insert plots that consist of a single panel. You've made a faceted plot, which contains multiple panels.

Claus Wilke
  • 16,992
  • 7
  • 53
  • 104