gpt4 book ai didi

r - 使用 ggplot2 绘制热图; logscale 颜色和修改颜色图例

转载 作者:行者123 更新时间:2023-12-02 07:11:58 26 4
gpt4 key购买 nike

我正在尝试用 ggplot2 创建一个热图(你看下面的代码)现在有两件事我想改变:

  1. 我绘制了 pValues(希望它非常小)所以我想绘制颜色对数标度。我尝试了不同变体的 trans="log",但没有一个起作用
  2. 我想在图例中显示 6 个以上的值。我试过了breaks, labels for that but this didn't work as well

    (p <- ggplot(dataPVal.m, aes(variable, structure)) + 
    geom_tile(aes(fill = pValue), colour = "white") +
    scale_colour_gradientn(colour = rainbow(100), breaks = c(1,2,3,4,5,6), labels =c("a","b","c","d","e","f")) +
    theme_grey(base_size = base_size) +
    labs(x = "position (0=seed start)",y = "structure") + ## labels
    #scale_x_discrete(expand = c(0.01, 0.01)) + ## grauer rand oben/unten
    #scale_y_discrete(expand = c(0.01, 0.01)) + ## grauer rand links/rechts
    opts(title=plot_title,legend.position = "left",axis.ticks = theme_blank(), axis.text.x = theme_text(size = base_size * 0.8, angle = 330, hjust = 0, colour = "grey50"))
    )

这里是 pValue 表 (dataPVal.m) 的示例:

        structure variable      value     pValue1          CB      -10 1.00000000 1.000000002          BB      -10 1.00000000 1.000000003          SC      -10 0.34700205 0.347002054          GC      -10 1.00000000 1.000000005          BC      -10 1.00000000 1.000000006          SG      -10 0.44494198 0.444941987          JG      -10 1.00000000 1.000000008          IG      -10 1.00000000 1.000000009          HG      -10 1.00000000 1.0000000010         CG      -10 1.00000000 1.0000000011         HH      -10 1.00000000 1.0000000012         GH      -10 0.34375000 0.0000002513         SI      -10 0.25000000 0.2500000014         JI      -10 0.40359735 0.4035973515         II      -10 1.00000000 1.0000000016         GI      -10 1.00000000 1.0000000017         SJ      -10 0.53296021 0.5329602118         IJ      -10 1.00000000 1.0000000019         GJ      -10 1.00000000 1.0000000020         US      -10 0.19567557 0.1956755721         SS      -10 0.43017585 0.0000003222         JS      -10 1.00000000 1.0000000023         IS      -10 1.00000000 1.0000000024         GS      -10 1.00000000 1.0000000025         CS      -10 1.00000000 1.0000000026         UU      -10 0.39863089 0.3986308927         SU      -10 0.50000000 0.5000000028         JU      -10 1.00000000 1.0000000029         CB       -9 0.34944171 0.3494417130         BB       -9 1.00000000 1.0000000031         SC       -9 0.53230531 0.53230531

有没有人能解决这两个问题?

谢谢这么久

最佳答案

当我插入时

+ scale_fill_gradient( trans = 'log' ) +

geom_tile(...) 之后它确实将填充比例更改为对数,pValue 有 8 个图例条目(e^0, e^(-2),...e^(-14))。那是你试过的吗?

关于r - 使用 ggplot2 绘制热图; logscale 颜色和修改颜色图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com