相关疑难解决方法(0)

是否可以避免轴标签被ggrepel重叠?

我正在用ggplot2绘制热图。y轴上的几个刻度需要标记。但是,其中一些过于紧密和重叠。我知道ggrepel可以分隔文本标签,但是目前我还没有解决我的问题。

我的代码如下。任何建议都欢迎。谢谢。

码:

df <- data.frame()

for (i in 1:50){
  tmp_df <- data.frame(cell=paste0("cell", i), 
                       gene=paste0("gene", 1:100), exp = rnorm(100), ident = i %% 5)
  df<-rbind(df, tmp_df)
}

labelRow=rep("", 100)
for (i in c(2, 5, 7, 11, 19, 23)){
  labelRow[i] <- paste0("gene", i)
}

library(ggplot2)
heatmap <- ggplot(data = df, mapping = aes(x = cell, y = gene, fill = exp)) +
  geom_tile() + 
  scale_fill_gradient2(name = "Expression") + 
  scale_y_discrete(position = "right", labels = labelRow) +
  facet_grid(facets = ~ident,
             drop = TRUE, …
Run Code Online (Sandbox Code Playgroud)

r facet ggplot2 cowplot ggrepel

7
推荐指数
1
解决办法
991
查看次数

标签 统计

cowplot ×1

facet ×1

ggplot2 ×1

ggrepel ×1

r ×1