gpt4 book ai didi

r - 根据条件为 geom_text 中的文本添加颜色

转载 作者:行者123 更新时间:2023-12-05 03:13:00 24 4
gpt4 key购买 nike

我正在绘制一个图,其中使用 geom_text 将 p 值绘制为文本。 pvalues 在文件 pvaluesmir21combined 中给出。

如果值 < 5e-02,我想为我的文本 (FDR) 添加红色。知道如何做到这一点吗?

ggplot(TumorNormalmiR21_5p.m3, aes(X2,value)) + 
geom_dotplot(aes(fill=variable),binaxis = "y") + coord_flip() +
theme_bw(base_size=8) +
theme(axis.text.y=element_text(hjust = 0)) +
geom_text(aes(x, y, label=FDR, group=NULL),data=pvaluesmir21combined,size=2)


> pvaluesmir21combined

FDR x y
1 p = 8.3e-02 1 13
2 p = 6.3e-05 2 13
3 p = 3.2e-17 3 13
4 p = 4.8e-22 4 13
5 p = 3.1e-10 5 13
6 p = 6.7e-11 6 13
7 p = 3.2e-24 7 13
8 p = 2.1e-06 8 13
9 p = 1.9e-02 9 13
10 p = 9.4e-06 10 13
11 p = 1.5e-03 11 13

最佳答案

您可以尝试使用函数 scale_color_manual

ggplot(TumorNormalmiR21_5p.m3, aes(X2,value)) + 
geom_dotplot(aes(fill=variable),binaxis = "y") + coord_flip() +
theme_bw(base_size=8) +
theme(axis.text.y=element_text(hjust = 0)) +
geom_text(aes(x, y, label=FDR, group=NULL, color = ifelse(as.numeric(sub("p = ", "", FDR)) < 5e-02, 0, 1),data=pvaluesmir21combined,size=2) +
scale_color_manual(values = c("red", "black"))

请参阅此链接 http://docs.ggplot2.org/0.9.3.1/scale_manual.html

关于r - 根据条件为 geom_text 中的文本添加颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31471456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com