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