R ggplot2: using stat_summary (mean) and logarithmic scale

前端 未结 3 1900
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 02:46

I have a bunch of measurements over time and I want to plot them in R. Here is a sample of my data. I\'ve got 6 measurements for each of 4 time points:

value         


        
相关标签:
3条回答
  • 2020-12-07 03:21

    A work around to solve it, if you don´t want to use coord_trans() and still want to transform the data, is to create a function which will back transform it:

    f1 <- function(x) {
      log10(mean(10 ^ x)) 
    }
    
    stat_summary (fun.y = f1, geom="line", mapping = aes (group = 1))
    
    0 讨论(0)
  • 2020-12-07 03:37

    The best solution I found for this issue was to use a combo of coord_trans() and scale_y_continuous(breaks = breaks)

    As previously suggested, using coord_trans will scale your axis without transforming the data, however it will leave you with an ugly axis.

    Setting the limits in coord_trans works for some things, but if you want to fix your axis to have specific labels, you will then include scale_y_continuous with the breaks you'd like set.

    coord_trans(y = 'log10') +
    scale_y_continuous(breaks = breaks)
    
    0 讨论(0)
  • 2020-12-07 03:47

    scale_y_log2() will do the transformation first and then calculate the geoms.

    coord_trans() will do the opposite: calculate the geoms first, and the transform the axis.

    So you need coord_trans(ytrans = "log2") instead of scale_y_log2()

    0 讨论(0)
提交回复
热议问题