我正在尝试在我使用 ggplot 创建的散点图旁边添加边际箱线图。为了添加边际箱线图,我使用了 cowplot 包(也是因为 ggmarginal 总是给我不同宽度的箱线图)。尽管如此,它仅适用于 x 轴而不适用于 y 轴。
data_merged %>%
filter(treatment !="ctr") %>%
split(.$compartment) %>%
map(
~ggplot(.,
aes(x=time_after_treatment, y=max_peak,
fill=treatment, colour=treatment))+
scale_colour_manual(values=c("#1f78b4", "#b2df8a", "#a6cee3")) +
scale_fill_manual(values=c("#1f78b4", "#b2df8a", "#a6cee3")) +
geom_point(size=3) +
scale_x_continuous(limits= c(2.5,17))+
scale_y_continuous (limits= c(0.4, 2.0, 0.5)) +
theme_classic() +
labs(y= Ca^"2+"~peak~(mu*M), x= "Time (min)") +
theme(#axis.title.x=element_blank(),
legend.position = "none",
axis.text=element_text(size=11),
panel.border = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_blank())
) -> list_scatter
data_merged %>%
filter(treatment !="ctr") %>%
filter(compartment == "cytosol") -> data_cyt
xbox_P3 <- axis_canvas(list_scatter[[1]], axis = "x", coord_flip = TRUE) +
geom_boxplot(data=data_cyt,
aes(y=time_after_treatment, x=treatment, fill=treatment))+
scale_fill_manual(values=c("#1f78b4", "#b2df8a", "#a6cee3"))+
scale_x_discrete() +coord_flip()
P3 <- insert_xaxis_grob(list_scatter[[1]], xbox_P3,
grid::unit(0.9, "in"), position="top")
P3_plot <- ggdraw(P3)
ybox_P4 <- axis_canvas(list_scatter[[2]], axis = "y") +
geom_boxplot(data=data_cyt,
aes(y=max_peak, x=treatment, fill=treatment))+
scale_fill_manual(values=c("#1f78b4", "#b2df8a", "#a6cee3"))+
scale_x_discrete()
zero_range(range) 错误:x 必须是长度 1 或 2
- stop("x 的长度必须是 1 或 2")
- zero_range(范围)
- scales::expand_range(range, expand[1], expand[2])
- get_scale_limits(layer_scales(plot)$y)
- axis_canvas(list_scatter[[2]], axis = "y")