Displaying minor logarithmic ticks in x-axis in R

前端 未结 8 552
一个人的身影
一个人的身影 2021-02-02 15:31

I have a normal distribution plot and a histogram plot with x axis in log scale displaying 0, 10^0, 10^1 ... I want to include minor ticks between the major ones. Actually I was

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-02 15:58

    In ggplot2, we can use annotation_logticks together with scales::trans_breaks and scales::trans_format. Below is an example taken from the link above.

        library(ggplot2)
    
        a <- ggplot(msleep, aes(bodywt, brainwt)) +
          geom_point(na.rm = TRUE) +
          scale_x_log10(
            breaks = scales::trans_breaks("log10", function(x) 10^x),
            labels = scales::trans_format("log10", scales::math_format(10^.x))
          ) +
          scale_y_log10(
            breaks = scales::trans_breaks("log10", function(x) 10^x),
            labels = scales::trans_format("log10", scales::math_format(10^.x))
          ) +
          theme_bw()
    
        a + annotation_logticks() # Default: log ticks on bottom and left
    

提交回复
热议问题