简体   繁体   中英

Ggplot2 - Simple Legend and Coloring

I understand that ggplot2 uses the concept of grammar of graphics. Here I'm trying to use a layered coloring scheme with a simple legend on the side, but I'm not having too much success. I'm wanting the first geom_point() below to be all in black, the second to be all in blue (for only statistically significant points), and the third in red. For the legend, I'm wanting black to be "not significant", blue to be "significant", and red to be "published genes". Can anyone help or provide some advice?

gene_count.poly <-
      ggplot() +
      labs(title="Poly Untreated vs. Treated",
           x ="log2(Poly Untreated)", y = "log2(Poly Treated)") +
      geom_point(data=normalized_all_counts.poly, aes(x=log2(avg_rep1),
                                                      y=log2(avg_rep2)), color="black") +
      geom_point(data=significant_normalized_all_counts.poly, aes(x=log2(avg_rep1),
                                                                  y=log2(avg_rep2)), color="blue") +
      geom_point(data=significant_normalized_all_counts.poly, aes(x=log2(avg_rep1),
                                                                  y=log2(avg_rep2)), color = significant_normalized_all_counts.poly$genecolor)
      
    
    
    print(gene_count.poly)

Here's an example of what you describe using the built-in mtcars dataset.

library(ggplot2); library(dplyr)
ggplot(mtcars, aes(wt, mpg)) +
  geom_point(data = filter(mtcars, mpg > 25),
             aes(color = "high mpg")) +
  geom_point(data = filter(mtcars, wt > 5),
             aes(color = "high weight")) +
  geom_point(data = filter(mtcars, wt == 3.44),
             aes(color = "one particular weight")) +
  scale_color_manual(values = c("high mpg" = "black",
                                "high weight" = "blue",
                                "one particular weight" = "red"))

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM