【问题标题】:transforming scale_colour_gradient to log2 space in ggplot2 in R在 R 中的 ggplot2 中将 scale_colour_gradient 转换为 log2 空间
【发布时间】:2013-06-18 21:33:48
【问题描述】:

如果我在 ggplot2 中有一个绘图,其中绘制的值转换为 log2,但也用作颜色值,如:

geom_line(aes(x=x, y=y, colour=y)) + scale_y_continuous(trans=scales.log2_trans()) + scale_colour_gradient()

我怎样才能让scale_colour_gradient 也显示 log2(不仅仅是 log)比例的值?数据框中的原始 y 值未记录。谢谢。

【问题讨论】:

    标签: r plot ggplot2


    【解决方案1】:

    您也可以在 scale_colour_gradient() 中使用转换,方法与在 scale_y_continuous() 中相同。

    df<-data.frame(x=1:100,y=1:100)
    library(scales)
    ggplot(df)+geom_line(aes(x=x, y=y, colour=y)) + 
      scale_y_continuous(trans=log2_trans()) + 
      scale_colour_gradient(trans=log2_trans())
    

    【讨论】:

    • 谢谢,跟进问:如果我现在想改变ys的颜色渐变的limits=,我是使用log值还是自然值?
    • @user248237dfsf 您使用自然值 - 转换是通过 trans=
    • 使用此转换结果为Error in inherits(x, "trans") : could not find function "log2_trans"。你现在需要,trans="log10"
    • @notconfusing 确实添加了library(scales) - 对我来说这没有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 2021-10-07
    相关资源
    最近更新 更多