0

I want to change the color of my points in the graph however the vector I created isn't doing that. All my code seems to be running fine but the graph won't print as how I want it.

The left side should be colored blue and the right side should be red.

# 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)
Genesis
  • 31
  • 1
  • 5
  • 1
    Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Aug 09 '20 at 00:37

1 Answers1

0

I'd create a new variable based on the value of logFC2, and colour it from there.

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))

followed by

geom_point(aes(colour = colour.grp)) +
scale_colour_manual(values = c("green", "red", "grey")

can't remember how to order them though.

Sarah
  • 25
  • 4