【问题标题】:scale_fill_viridis_c color bar on a log scale对数刻度上的 scale_fill_viridis_c 颜色条
【发布时间】:2019-12-23 03:24:48
【问题描述】:

我希望这不是重复的,但我不能再上网了。我真的很想生成一个热图,但颜色条是对数刻度。我不一定要将我的值转换为日志,而是更改颜色条,使其从0, 0.01, 0.1, 1, 10, 100 运行。我包含了一个表示我正在使用的数据示例的代表,下面是我希望重述的一篇论文中的一个数字。

library(tidyverse)

my_data <- tibble(sample_name = rep(c("A", "B", "C"), 3),
                  sample_genus = c(rep("Genus1", 3), rep("Genus2", 3),rep("Genus3", 3)),
                  sample_abundance = c(0,5,45,0.3,0.01,15,1,8,89))

ggplot(data = my_data, aes(x = sample_name,
                           y = sample_genus,
                           fill = sample_abundance)) +
  geom_tile() +
  scale_fill_viridis_c(limits = c(0, 100))

reprex package (v0.3.0) 于 2019-08-16 创建

【问题讨论】:

标签: r ggplot2


【解决方案1】:

这是一种使用scales::pseudo_log_trans 的方法,它允许我们绘制 0,但转换为超过 1 的对数缩放。

my_breaks <- c(0, 0.01, 0.1, 1, 10, 100)

ggplot(data = my_data, aes(x = sample_name,
                           y = sample_genus,
                           fill = sample_abundance)) +
  geom_tile() +
  scale_fill_viridis_c(breaks = my_breaks, labels = my_breaks, 
                       trans = scales::pseudo_log_trans(sigma = 0.001))

【讨论】:

    猜你喜欢
    • 2013-02-21
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    相关资源
    最近更新 更多