使用ggrepel组织标签

问题描述 投票:0回答:1

我想在火山图中标记尊重表达的基因。我尝试过使用

geom_label_repel
函数中的参数,但标签很混乱。

有什么方法可以组织它们,特别是让蓝色标签粘在左侧,反之亦然?

resLFC <- read.delim("resLFC f2 vs f1 chronic.txt")
ggplot(data= resLFC, aes(x= log2FoldChange, y= -log10(padj), col=diffs, label=delabel))+
  coord_cartesian(xlim = c(-20,20), ylim= c(0,80))+
  geom_vline(xintercept = c(-1, 1), col="blue", linetype="dashed")+
  geom_hline(yintercept = 4, col= "red", linetype="dashed") +
  geom_point()+
  scale_color_manual(values = c("dodgerblue1", "gray", "deeppink1"),
                     labels = c("Downregulated", "Not significant", "Upregulated"))+
  labs(color = "x",
       x= expression("log"[2]*"FC"), y= expression("-log"[10]*"p-value"))+
  geom_label_repel(nudge_x = c(-10,10), nudge_y = c(0,20),force=10, max.iter=20000, max.segment.length = 0.01, max.overlaps = 1000)+
  theme(legend.position = c(0.88, 0.88))
r ggplot2 label
1个回答
0
投票

您可以尝试根据“x”变量将数据分成两组(下调与上调),然后调用 geom_label_repel 函数两次,每组一次,摆弄“nudge_x”参数。

使用 mtcars 数据集的示例,我在中值 wt 上进行分割:

library(ggplot2)

cars1 <- filter(mtcars, wt<median(wt))
cars2 <- filter(mtcars, wt>=median(wt))

ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point() +
  geom_vline(xintercept = median(mtcars$wt), col="blue", linetype="dashed") +
  geom_label_repel(data=cars1, nudge_x = -1, label=rownames(cars1)) +
  geom_label_repel(data=cars2, nudge_x = +1, label=rownames(cars2)) 

© www.soinside.com 2019 - 2024. All rights reserved.