【问题标题】:Ggplot2 - Simple Legend and ColoringGgplot2 - 简单的图例和着色
【发布时间】:2023-03-24 02:25:01
【问题描述】:

我了解ggplot2使用了图形语法的概念。在这里,我尝试使用带有简单图例的分层着色方案,但我并没有取得太大的成功。我希望下面的第一个 geom_point() 全部为黑色,第二个全部为蓝色(仅用于统计显着点),第三个为红色。对于传说,我希望黑色是“不重要的”,蓝色是“重要的”,红色是“已发表的基因”。任何人都可以提供帮助或提供一些建议吗?

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)

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    这是您使用内置 mtcars 数据集描述的示例。

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

    【讨论】:

    • 谢谢,这完美地回答了我的问题。
    猜你喜欢
    • 2019-12-04
    • 2022-01-08
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多