How to get a reversed, log10 scale in ggplot2?

前端 未结 2 775
执念已碎
执念已碎 2020-11-27 17:19

I\'d like to make a plot with a reversed, log10 x scale using ggplot2:

require(ggplot2)
df <- data.frame(x=1:10, y=runif(10))
p <- ggplot(data=df, aes(         


        
2条回答
  •  爱一瞬间的悲伤
    2020-11-27 18:14

    ggforce package has trans_reverser() function for this task.

    library(ggplot2)
    library(ggforce)
    
    p <- ggplot() +
      geom_line(aes(x = 1:100, y = 1:100))
    
    p +
      scale_x_continuous(trans = trans_reverser('log10')) +
      annotation_logticks(sides = 'tb') +
      theme_bw()
    

    Created on 2020-11-14 by the reprex package (v0.3.0)

提交回复
热议问题