GGplot custom scale transformation with custom ticks

前端 未结 1 467
故里飘歌
故里飘歌 2020-12-04 00:35

I\'m attempting to use a custom scale/axis transformation, like so:

library(ggplot2)
library(scales)

dat <- data.frame(
  time.tot = c(407.17, 168.83, 12         


        
相关标签:
1条回答
  • 2020-12-04 01:03

    You may need to set the scale on the y axis directly:

    ggplot(dat, aes(x=time.tot, y=error, color=type)) +
      geom_line() + geom_point() + coord_trans(y = tn)
      + scale_y_continuous(breaks = c(0,0.1,1))
    

    Also, the non-straight lines are the expected behavior of coord_trans. from the help: "coord_trans is different to scale transformations in that it occurs after statistical transformation and will affect the visual appearance of geoms - there is no guarantee that straight lines will continue to be straight."

    Instead, try:

    b <- 10^-c(Inf, 8:0)
    ggplot(dat, aes(x=time.tot, y=error, color=type)) +
      geom_line() + geom_point() + scale_y_continuous(breaks = b, labels=b, trans = tn)
    

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