0

How do I make the y-axis log 10 scale? hist(Data, breaks = 50) I'm very new to R programming, any help here would be much appreciated.

  • maybe this helps https://stackoverflow.com/questions/1245273/histogram-with-logarithmic-scale-and-custom-breaks – Sphinx Mar 03 '21 at 16:43
  • 1
    It's difficult to log-scale the y-axis of bar plots and histograms because the y axis typically starts at 0, and `log(0)` is `-Inf`. Maybe try a square root scale instead? – Gregor Thomas Mar 03 '21 at 20:03
  • https://stackoverflow.com/a/1257851/190277 – Ben Bolker Mar 03 '21 at 20:10

1 Answers1

0

Here are two potential options below.

  1. The easiest way to plot on a log10 scale is to use the scale_y_log10 if you are using ggplot2 (ggplot2 reference here: https://ggplot2.tidyverse.org/reference/scale_continuous.html)

  2. Apply the transformation to the data itself. Solutions using both dplyr and base r are listed below:

dplyr: Data2 <- Data %>% mutate(logy = log10(yvariable))

base:

logy <- data.frame(log10(Data$yvariable))

Data2 <- cbind(Data, logy)

Adam
  • 433
  • 2
  • 16