将scale_colour_gradient转换为R中ggplot2中的log2空间

2 plot r ggplot2

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

geom_line(aes(x=x, y=y, colour=y)) + scale_y_continuous(trans=scales.log2_trans()) + scale_colour_gradient()
Run Code Online (Sandbox Code Playgroud)

如何才能scale_colour_gradient在log2(而不仅仅是log)中显示值?y数据框中的原始值未记录.谢谢.

Did*_*rts 5

您也可以使用scale_colour_gradient()与in中相同的方式使用转换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())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @ user248237dfsf您使用自然值 - 通过trans =在限制上完成转换 (2认同)