如何在绘图子区域中添加阴影并使用ggrepel标记数据点的子集?

9
我制作了这个火山图并希望进行以下改进: made this Volcano plot
  1. 完全用蓝色数据点填充该区域:使用当前代码,我无法将阴影延伸到超出现有范围。我希望它能够覆盖整个绘图区域。
  2. geom_text 允许我标记数据点的子集,但使用 ggrepel 可以添加连接数据点和标签的线条,从而提高标签清晰度。如何重用 ggrepel 中已有的 geom_text 代码来实现这一点?
这是我的代码:
ggplot(vol.new, aes(x = log2.fold.change, y = X.NAME., fill = Color)) + # Define data frame to be used for plotting; define data for x and y axes; crate a scatterplot object.

  geom_point(size = 2, shape = 21, colour = "black") + # Define data point style.

  ggtitle(main.title, subtitle = "Just a little subtitle") + # Define title and subtitle.

  labs(x = x.lab, y = y.lab) + # Define labels for x and y axes.

  scale_x_continuous(limits = c(-3, 3), breaks = seq(-3, 3, by = 0.5)) + # Define x limits, add ticks.
  scale_y_continuous(limits = c(0, 6), breaks = seq(0, 6, by = 1)) + # Define y limits, add ticks.

  theme(
    plot.title = element_text(family = "Arial", size = 11, hjust = 0), # Title size and font.
    plot.subtitle = element_text(family = "Arial", size = 11), # Subtitle size and font.
    axis.text = element_text(family = "Arial", size = 10), # Size and font of x and y values.
    axis.title = element_text(family = "Arial", size = 10), # Size and font of x and y axes.
    panel.border = element_rect(colour = "black", fill = NA, size = 1), # Black border around the plot area.
    axis.ticks = element_line(colour = "black", size = 1), # Style of x and y ticks.
    legend.position = "none"
  ) + # Remove legend.

  geom_hline(yintercept = 1.30103, colour = "black", linetype = "dashed", size = 0.75) + # Horizontal significance cut-off line.
  geom_vline(xintercept = 0.584963, colour = "black", linetype = "dashed", size = 0.75) + # Vertical significance cut-off line (+).
  # geom_vline (xintercept = -0.584963, colour = "black", linetype = "dashed", size = 0.75) #Vertical significance cut-off line (-)

  scale_fill_manual(breaks = c("blue", "red"), values = c("deepskyblue3", "firebrick1")) + # Costum colors of data points based on "PursFur" column.

  geom_text(aes(label = ifelse(PursFur == 1, as.character(Protein.ID), "")), hjust = 0, vjust = -0.25) + # Add identifiers to a subset of data points.

  annotate("text", x = 2.9, y = 1.45, label = "P = 0.05", size = 4, fontface = "bold") + # Label to horizontal cut-off line.
  annotate("text", x = 0.68, y = 5.9, label = "1.5-fold", size = 4, fontface = "bold", srt = 90) + # Label to vertical cut-off line.
  annotate("rect", xmin = 0.584963, xmax = 3, ymin = 1.30103, ymax = 6, alpha = .2) # Shade plot subregion.

3
您可以使用“-Inf”和“Inf”作为x或y的最小或最大值。另外:第一个问题。 - hrbrmstr
有一个用于火山图的软件包,请参见:https://github.com/kevinblighe/EnhancedVolcano - zx8754
有关着色的相关帖子:https://dev59.com/AGkw5IYBdhLWcg3wVpFi - zx8754
@zx8754,我已经看到了EnhancedVolcano。我会测试一下。谢谢你提供相关的帖子链接! - JernejT
2个回答

6

如@hrbrmstr和@zx8754在评论中建议的那样,这是我对上面代码所做的修改。

为解决阴影问题(来自@hrbrmstr):

annotate ("rect", xmin = 0.584963, xmax = Inf, ymin = 1.30103, ymax = Inf, alpha = .2)

为了解决标签问题(通过@zx8754提供):
geom_label_repel (aes (label = ifelse (PursFur == 1, as.character (Protein.ID), '')), nudge_x = 1.3, direction = "x")

这是这两个更改后的结果: enter image description here 想深入了解我最初问题的第二部分,可以查看这个网站这个不错的ggrepel教程

只需将“geom_text”替换为“geom_text_repel”。 - zx8754
如果问题得到解决,请接受答案:https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work - zx8754

1
使用以下代码实现了另一种标签方案:
 geom_label_repel (aes (label = ifelse (PursFur == 1, as.character (Protein.ID),'')), 
                        nudge_x = 4, direction = "y",
                        arrow = arrow (length = unit (0.02, "npc"), type = "closed", ends = "last", angle = 15),
                        fill = "white")

并且得到的绘图现在看起来像这样:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接