Youtube channel: https://www.youtube.com/c/TechAnswers88

Direct link to the video describing all types of log scales in your ggplot charts with explaination.

https://youtu.be/rr5MpbFv3mk

library(patchwork)
library(ggplot2)



cases <- data.frame( 
   c('A','B','C','D'),         
       c(1,2,3,500))
names(cases) <- c('Name', 'Count')

pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + ggtitle('Original chart')
pl

pl1 <- pl

pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log2")
pl <- pl + ggtitle('Log2 scale on Y axis')
pl

pl2 <- pl


pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log2", breaks = c(2,4,8,8,16,32,64, 128,256,512))
pl <- pl + ggtitle('Log2 scale on Y axis with defined breaks')
pl3 <- pl



library(scales)
pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log2"
                              , breaks =  trans_breaks("log2", function(x) 2^x)
                              , labels = trans_format("log2", math_format(2^.x)))
pl <- pl + ggtitle('Log2 scale on Y axis with exponential breaks')
pl

pl4 <- pl


pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log10")
pl <- pl + ggtitle('Log10 scale on Y axis')
pl

pl5 <- pl

pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl +  scale_y_log10()
pl <- pl + ggtitle('Log10 scale using scale_y_log10')
pl

pl6 <- pl

pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log10", breaks = c(1,2,4,6,8, 10,50,100,500,1000))
pl <- pl + ggtitle('Log10 scale on Y axis with custom defined breaks')
pl

pl7 <- pl


pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl +  scale_y_log10()
pl <- pl + ggtitle('Original Plot')
pl

pl8 <- pl


pl <- ggplot(data = cases, aes(x = Name, y = Count))
pl <- pl + geom_bar(stat ="identity")
pl <- pl  + theme_classic()
pl <- pl + scale_y_continuous(trans = "log10"
                              , breaks =  trans_breaks("log10", function(x) 10^x)
                              , labels = trans_format("log10", math_format(10^.x)))
pl <- pl + ggtitle('Log10 scale on Y axis with exponential breaks')
pl

pl9 <- pl



# Showing all charts for easy comparison
pl1 + pl2 + pl3 + pl4 + pl5 + pl6 + pl7 + pl8 + pl9