1

我对编程很陌生,但我设法使用以下链接中的建议为散点图制作多面散点图和边际箱线图:http ://www.lreding.com/nonstandard_deviations/2017/08/19/cowmarg/

我的问题是如何在多面散点图上制作边际箱线图?

我的代码是:

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

简单的散点图:

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

黑白散点图:

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

带有标记轴的散点图:

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

带有标记轴和经典主题的散点图:

sc_lab_th<-sc_lab+theme_classic()
sc_lab_th

带有标记轴的散点图和具有更改形状的经典主题:

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

带有刻面和白色/灰色的箱线图:

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"))

在这里我得到了一个错误:

get_panel(grob) 中的错误:绘图必须只包含一个面板

4

1 回答 1

0

答案是:你不能。(至少不是通过axis_canvas()/insert_yaxis_grob()路线。错误消息会告诉您到底发生了什么:该函数insert_yaxis_grob()只能插入由单个面板组成的图。您已经制作了一个包含多个面板的多面图。

于 2017-12-13T04:22:38.127 回答