transforming axis labels with a multiplier ggplot2

后端 未结 1 749
别跟我提以往
别跟我提以往 2021-01-05 01:37

Previously in ggplot2, I used a formatter function to multiply values in the Y axis by 100:

formatter100 <- function(x){ 
x*100 }

With t

相关标签:
1条回答
  • 2021-01-05 02:27

    Transformations actually transform the scale itself. In the case of your y axis, you're just formatting the breaks. So you don't really want to use trans_new, just a regular format function. Similarly, you want to use comma_format rather than comma, as the former actually returns a function as needed:

    mult_format <- function() {
         function(x) format(100*x,digits = 2) 
    }
    p <- ggplot( test, aes(lat, ecdf) ) 
    p<-p + 
      geom_point()+
      scale_x_log10(breaks = xbreaks,labels = comma_format()) +
      scale_y_continuous(trans='probit', 
                         labels = mult_format(), 
                         breaks=ybreaks) + 
      xlab("latency ms")
    p
    

    enter image description here

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