【发布时间】:2020-08-12 02:36:43
【问题描述】:
我想更改图表中点的颜色,但是我创建的矢量没有这样做。我的所有代码似乎都运行良好,但图表不会按我想要的方式打印。
左侧应为蓝色,右侧应为红色。
# 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)
【问题讨论】:
-
欢迎来到 Stack Overflow!您能否通过共享您的数据样本来重现您的问题,以便其他人可以提供帮助(请不要使用
str()、head()或屏幕截图)?您可以使用reprex和datapasta包来帮助您。另见Help me Help you & How to make a great R reproducible example?