散点图 - "if"、"and" 条件的多种颜色
Scatterplot - multiple colours for "if", "and" conditions
我需要在有多个条件的散点图中指定颜色。
该文件在下面 df
。
我正在绘制 Tissue1
与 Tissue2
值。我想着色如下:
pvalue1 AND pvalue2 < 0.1 = "yellow"
pvalue1 ≤ 0.1 = "green" (if pvalue2 >0.1 or NA)
pvalue2 ≤ 0.1 = "red" (if pvalue1 >0.1 or NA)
(all other = "grey")
df:
rowname Tissue1 pvalue1 Tissue2 pvalue2
gene1 1.3 0.7 1.6 0.09
gene2 -0.9 0.07 -0.7 0.065
gene3 2 0.9 1.65 0.9
gene4 1.7 0.07 1.6 0.09
我正在使用 ggplot 绘制 Tissue1 与 Tissue2:
ggplot(data=data.frame(x=df$Tissue1,y=df$Tissue2),
aes(x,y)
)+ geom_point(col="grey30") +
geom_abline(stat = "abline", colour = "red", size = 1) +
xlab("foldchange Tissue1") + ylab("foldchange Tissue2")
我试过创建因子,但无法使用 ifelse 函数添加它们。
Sig1 <- subset(df, df$pvalue1< 0.1)
Sig2 <- subset(df, df$pvalue2 < 0.1)
非常感谢您对此提供帮助。
谢谢!
DF <- read.table(text = "rowname Tissue1 pvalue1 Tissue2 pvalue2
gene1 1.3 0.7 1.6 0.09
gene2 -0.9 0.07 -0.7 0.065
gene3 2 0.9 1.65 0.9
gene4 1.7 0.07 1.6 0.09", header = TRUE)
#the order of the following lines is important
DF$col <- "grey"
DF[!is.na(DF$pvalue1) & DF$pvalue1 <= 0.1 , "col"] <- "green"
DF[!is.na(DF$pvalue2) & DF$pvalue2 <= 0.1 , "col"] <- "red"
DF[!is.na(DF$pvalue1) & !is.na(DF$pvalue2) &
DF$pvalue1 < 0.1 & DF$pvalue2 < 0.1,
"col"] <- "yellow"
library(ggplot2)
ggplot(DF, aes(x = Tissue1, y = Tissue2, color = col)) +
geom_point() +
geom_abline(stat = "abline", colour = "red", size = 1) +
xlab("foldchange Tissue1") + ylab("foldchange Tissue2") +
scale_color_identity()
我需要在有多个条件的散点图中指定颜色。
该文件在下面 df
。
我正在绘制 Tissue1
与 Tissue2
值。我想着色如下:
pvalue1 AND pvalue2 < 0.1 = "yellow"
pvalue1 ≤ 0.1 = "green" (if pvalue2 >0.1 or NA)
pvalue2 ≤ 0.1 = "red" (if pvalue1 >0.1 or NA)
(all other = "grey")
df:
rowname Tissue1 pvalue1 Tissue2 pvalue2
gene1 1.3 0.7 1.6 0.09
gene2 -0.9 0.07 -0.7 0.065
gene3 2 0.9 1.65 0.9
gene4 1.7 0.07 1.6 0.09
我正在使用 ggplot 绘制 Tissue1 与 Tissue2:
ggplot(data=data.frame(x=df$Tissue1,y=df$Tissue2),
aes(x,y)
)+ geom_point(col="grey30") +
geom_abline(stat = "abline", colour = "red", size = 1) +
xlab("foldchange Tissue1") + ylab("foldchange Tissue2")
我试过创建因子,但无法使用 ifelse 函数添加它们。
Sig1 <- subset(df, df$pvalue1< 0.1)
Sig2 <- subset(df, df$pvalue2 < 0.1)
非常感谢您对此提供帮助。 谢谢!
DF <- read.table(text = "rowname Tissue1 pvalue1 Tissue2 pvalue2
gene1 1.3 0.7 1.6 0.09
gene2 -0.9 0.07 -0.7 0.065
gene3 2 0.9 1.65 0.9
gene4 1.7 0.07 1.6 0.09", header = TRUE)
#the order of the following lines is important
DF$col <- "grey"
DF[!is.na(DF$pvalue1) & DF$pvalue1 <= 0.1 , "col"] <- "green"
DF[!is.na(DF$pvalue2) & DF$pvalue2 <= 0.1 , "col"] <- "red"
DF[!is.na(DF$pvalue1) & !is.na(DF$pvalue2) &
DF$pvalue1 < 0.1 & DF$pvalue2 < 0.1,
"col"] <- "yellow"
library(ggplot2)
ggplot(DF, aes(x = Tissue1, y = Tissue2, color = col)) +
geom_point() +
geom_abline(stat = "abline", colour = "red", size = 1) +
xlab("foldchange Tissue1") + ylab("foldchange Tissue2") +
scale_color_identity()