用于标记散点图中特定点的gghighlight

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

我有一个如下所示的数据框:

 rowname  Class Sec    ES.2um Mean_WPBs   ES.2um_ZS   Mean_ES  VWF_Sec    name
       1 Formin HAI 113.37340  147.1792  0.16078492 131.69309 162.5219  DIAPH1
       2 Formin HAI  43.90661  121.9017 -0.11594028  75.37296 137.4212    FMN2
       3 Septin HAI  64.32138  132.7591 -0.16218581  66.23765 195.9011 SEPTIN5
       4 Septin HAI  53.15791  145.7871 -0.86969449  81.92690 187.2647   LRCH3
       5 Arp2/3 HAI  68.67222  161.0516 -0.05404113  82.51804 158.2623   ARPC3
       6 Arp2/3 HAI  71.00643  149.0704 -0.38119473  82.91458 220.5494   WASF3

目前我正在使用来识别/突出一类蛋白质;看下面的代码:

plot_ESZ_lab <-ggplot(df, aes(ES.2um_ZS, VWF_Sec, color = Sec, shape = Sec)) + 
               geom_point(aes(size = Mean_ES)) + 
               scale_size_continuous(range=c(0.5,10))+ 
               scale_color_manual(values=c("HAI" = "blue", "PMA" = "red")) + 
               gghighlight(Class == "Formin", use_direct_label = TRUE, 
                           label_key = name, label_params = list(size=2)) + 
               xlab("Mean Exit Site Z-Score") + ylab("Secretion") + 
               ggtitle("Formin Highlighted") + 
               theme_bw() + theme(plot.title = element_text(hjust =0.5))

我还想用他们的名字突出显示2或3个蛋白质;这是我试过的:

plot_ESZ_lab <-ggplot(df, aes(ES.2um_ZS, VWF_Sec, color = Sec, shape = Sec)) + 
               geom_point(aes(size = Mean_ES)) + 
               scale_size_continuous(range=c(0.5,10))+ 
               scale_color_manual(values=c("HAI" = "blue", "PMA" = "red")) + 
               gghighlight(Class == "Formin", name == "FMN2", "DIAPH1", 
                           use_direct_label = TRUE, label_key = name,
                           label_params = list(size=2)) + 
               xlab("Mean Exit Site Z-Score") + ylab("Secretion") +
               ggtitle("Formin Highlighted") + 
               theme_bw() + theme(plot.title = element_text(hjust =0.5))

但只提供给(即FMN2)的第一个名字。如何绘制超过1个点,即在这种情况下FMN2DIAPH1

r ggplot2
1个回答
1
投票

ggplot中的几乎所有函数中,,用于分隔不同的参数。您不能使用它为同一个变量提供多个输入。你需要写name %in% c("FMN2", "DIAPH1"),翻译为name等于FMN2DIAPH1;以下代码有效:

ggplot(df, aes(ES.2um_ZS, VWF_Sec, color = Sec, shape = Sec)) + 
      geom_point(aes(size = Mean_ES)) + 
      scale_size_continuous(range=c(0.5,10))+ 
      scale_color_manual(values=c("HAI" = "blue", "PMA" = "red")) + 
      gghighlight(Class == "Formin", name %in% c("FMN2", "DIAPH1"), 
                  use_direct_label = TRUE, label_key = name,
                  label_params = list(size=2)) + 
      xlab("Mean Exit Site Z-Score") + ylab("Secretion") +
      ggtitle("Formin Highlighted") +  
      theme_bw() + theme(plot.title = element_text(hjust =0.5))

            https://i.stack.imgur.com/XcjQZ.png

数据:

    df <- structure(list(rowname = 1:6, Class = structure(c(2L, 2L, 3L, 
    3L, 1L, 1L), .Label = c("Arp2/3", "Formin", "Septin"), class = "factor"), 
    Sec = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "HAI", class = "factor"), 
    ES.2um = c(113.3734, 43.90661, 64.32138, 53.15791, 68.67222, 
    71.00643), Mean_WPBs = c(147.1792, 121.9017, 132.7591, 145.7871, 
    161.0516, 149.0704), ES.2um_ZS = c(0.16078492, -0.11594028, 
    -0.16218581, -0.86969449, -0.05404113, -0.38119473), Mean_ES = c(131.69309, 
    75.37296, 66.23765, 81.9269, 82.51804, 82.91458), VWF_Sec = c(162.5219, 
    137.4212, 195.9011, 187.2647, 158.2623, 220.5494), name = structure(c(2L, 
    3L, 5L, 4L, 1L, 6L), .Label = c("ARPC3", "DIAPH1", "FMN2", 
    "LRCH3", "SEPTIN5", "WASF3"), class = "factor")), class = "data.frame",
     row.names = c("1", "2", "3", "4", "5", "6"))
© www.soinside.com 2019 - 2024. All rights reserved.