Hello,
I think ggplot is inconsistent in how it treats -inf in log scale. Below are two plots that display similar information. In the first case, I use a box plot to show the 25th, 50th, and 75th percentiles of the example dataset on a log scale. As you can see, it removes the 0 (or - inf values on the log scale) and creates the box plot from the remaining data points.
In the second example, I precalculate the 25th, 50th, and 75th percentiles and then use geom_point to make a similar plot with log scales. In this case, the zero value is simply plotted at the bottom of the axis instead of being removed. I think this behaviour is better. Is there a way to plot the box plot without removing the -inf values?
Thanks a lot.
library(tidyverse)
# create dataset
Test_Data <- data.frame("Values" = seq(0,10000,1))
Test_Data$Values[Test_Data$Values%%3==0] <- 0
Test_Data$Groups[Test_Data$Values%%2==0] <- 'A'
Test_Data$Groups[Test_Data$Values%%2!=0] <- 'B'
Test_Data$Values <- Test_Data$Values/10000
# plot boxplot
ggplot(data = Test_Data, aes(x= Groups, y = Values)) +
geom_boxplot()+
scale_y_continuous(trans='log10', limits = c(1e-5, 1e1)) +
annotation_logticks(sides = "l")
# Create dataset with quantile measures
Test_Data_Processed <- Test_Data %>%
select_all() %>%
group_by(Groups) %>%
summarise(Num = n(),
Median = median(Values),
Percnt_25 = quantile(Values,.25),
Percnt_75 = quantile(Values, .75)) %>%
gather(Measure, Value, Median:Percnt_75)
# plot with geom_point
ggplot(data = Test_Data_Processed, aes(x= Groups, y = Value, shape = Measure, color = Groups)) +
geom_point(size = 4) +
scale_y_continuous(trans='log10', limits = c(1e-5, 1e1)) +
annotation_logticks(sides = "l")