我想要改变图中点的颜色,但是我创建的向量并没有这样做。我的所有代码似乎都运行得很好,但是图形不能按照我想要的方式打印出来。
左边应该是蓝色,右边应该是红色。
# Basic Volcano Plot
VP <- ggplot(df.7vsNO, aes(x = log2FC, y = logpv)) + geom_point() + theme_minimal()
print(VP)
VP2 <- VP + geom_vline(xintercept=c(-1.6, 1.6), col="red") +
geom_hline(yintercept=-log10(0.05), col="red")
print(VP2)# add a column of NAs
df.7vsNO$diffexpressed <- "NO"
# if log2FoldChange > 1, set as "UP"
df.7vsNO$diffexpressed[df.7vsNO$log2FC > 1] <- "UP"
#if log2FoldChange < 1, set as "DOWN"
df.7vsNO$diffexpressed[df.7vsNO$log2FC < 1] <- "DOWN"# Re-plot but this time time color the points w/ "diffexpressed"
VP <- ggplot(df.7vsNO, aes(x = log2FC, y = logpv, col(diffexpressed))) + geom_point() + theme_minimal()
print(VP)
# Add lines as before...
VP2 <- VP + geom_vline(xintercept=c(-1.6, 1.6), col="red") +
geom_hline(yintercept=-log10(0.05), col="red")
print(VP2)# Change point color
VP3 <- VP2 + scale_color_manual(values=c("blue", "black", "red"))
# named vector
mycolors <- c("blue", "red", "black")
names(mycolors) <- c("DOWN", "UP", "NO")
VP3 <- VP2 + scale_color_manual(values = mycolors)
print(VP3)发布于 2020-08-09 09:13:31
我会根据logFC2的值创建一个新变量,并从那里给它上色。
library(dplyr)
df.7vsNO %>%
mutate(colour.grp = ifelse(logGC > 1.6, yes = "above", no = "nothing")) %>%
mutate(colour.grp = ifelse(logGC < -1.6, yes = "below", no = colour.grp))紧接着是
geom_point(aes(colour = colour.grp)) +
scale_colour_manual(values = c("green", "red", "grey")但是我不记得怎么排序了。
https://stackoverflow.com/questions/63321410
复制相似问题