我有一个看起来像这样的数据框:
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
,目前正在使用gghighlight来识别/突出显示一类蛋白质;看下面的代码:
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))
,但只会绘制提供给gghighlight的名字(即FMN2
)。如何获得超过1个点,即在这种情况下为FMN2
和DIAPH1
?
答案 0 :(得分:1)
在ggplot
中,并且通常在r中几乎所有函数中, ,
用于分隔不同的参数。您不能使用它为同一变量提供多个输入。您需要编写name %in% c("FMN2", "DIAPH1")
,翻译为name
等于FMN2
或DIAPH1
;下面的代码有效:
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))
数据:
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"))