【发布时间】:2021-01-16 16:41:06
【问题描述】:
enter image description here我制作了一个包含 16 个不同簇的堆叠小提琴图。我也附上了图。 代码如下:
modify_vlnplot<- function(obj, feature, pt.size = 0,
plot.margin = unit(c(-0.75, 0, -0.75, 0), "cm"),
...) {
p<- VlnPlot(obj, features = feature, pt.size = pt.size, ... ) +
xlab("") + ylab(feature) + ggtitle("") +
theme(legend.position = "none",
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_text(size = rel(1), angle = 0),
axis.text.y = element_text(size = rel(1)),
plot.margin = plot.margin )
return(p)
}
extract_max<- function(p){
ymax<- max(ggplot_build(p)$layout$panel_scales_y[[1]]$range$range)
return(ceiling(ymax))
}
StackedVlnPlot<- function(obj, features,
pt.size = 0,
plot.margin = unit(c(-0.75, 0, -0.75, 0), "cm"),
...) {
plot_list<- purrr::map(features, function(x) modify_vlnplot(obj = obj,feature = x, ...))
plot_list[[length(plot_list)]]<- plot_list[[length(plot_list)]] +
theme(axis.text.x=element_text(angle = 45, hjust = 1, vjust = 1),
axis.ticks.x = element_line())
#change the y-axis tick to only max value
ymaxs<- purrr::map_dbl(plot_list, extract_max)
plot_list<- purrr::map2(plot_list, ymaxs, function(x,y) x +
scale_y_continuous(breaks = c(y)) +
expand_limits(y = y))
p<- patchwork::wrap_plots(plotlist = plot_list, ncol = 1)
return(p)
}
StackedVlnPlot(obj = S1, features = features)
#Stacked violine plots
现在,我想绘制一个 5 列而不是 16 列的图。四个选定的簇/列和最后一列包含其余簇 (12) 的总/平均表达。请告诉我我该怎么做。提前致谢,期待积极响应。
【问题讨论】:
-
您应该添加
features的样本来重现您的代码。 -
Seurat 的 VlnPlot() function 现在有一个参数“stack=TRUE”,可以节省一些自定义代码。
标签: r