Apply two transformations on one axis

后端 未结 3 897
一生所求
一生所求 2021-01-21 02:16

I have found coord_trans, but I\'d like to apply log10 and reverse to my x-axis. I tried applying two transformation

ggplo         


        
3条回答
  •  [愿得一人]
    2021-01-21 02:57

    You can define new transformations using trans_new.

    library(scales)
    log10_rev_trans <- trans_new(
      "log10_rev",
      function(x) log10(rev(x)),
      function(x) rev(10 ^ (x)),
      log_breaks(10),
      domain = c(1e-100, Inf)
    )
    
    p <- ggplot(mtcars, aes(wt, mpg)) +
       geom_point()   
    
    p + coord_trans(y = log10_rev_trans)
    

提交回复
热议问题