Pretty ticks for log normal scale using ggplot2 (dynamic not manual)

后端 未结 5 729
挽巷
挽巷 2020-11-28 06:23

I am trying to use ggplot2 to create a performance chart with a log normal y scale. Unfortunately I\'m not able to produce nice ticks as for the base plot function.

5条回答
  •  感情败类
    2020-11-28 06:41

    The base graphics function axTicks() returns the axis breaks for the current plot. So, you can use this to return breaks identical to base graphics. The only downside is that you have to plot the base graphics plot first.

    library(ggplot2)
    library(scales)
    
    
    plot(M, type="l",log="y")
    breaks <- axTicks(side=2)
    ggplot(M,aes(x=X,y=Y)) + geom_line() +
      scale_y_continuous(breaks=breaks) +
      coord_trans(y="log")
    

    enter image description here

提交回复
热议问题