mara
February 11, 2019, 12:13pm
2
Hi,
I see that you've also posted this as an issue on GitHub:
opened 01:10PM - 10 Feb 19 UTC
closed 02:52PM - 22 May 19 UTC
Hello,
I think ggplot is inconsistent in how it treats -inf in log scale. Bel… ow 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")
```
If you cross-post issues here and on GitHub (or, as sometimes happens, it becomes apparent that something posted to the forum is an actual bug in the package, and an issue is filed as a result) we ask that you also post the link to the issue here, so that others can follow the progress.
Please see our FAQ on cross-posting below:
Posting the same question both here and on other sites
Posting the same question to multiple forums at the same time is often considered impolite. We don't completely ban such cross-posting, but we ask you to think hard before you do it and to follow some rules.
Cross-post sparingly
Rather than post the same thing here and elsewhere from the get-go, post in one place at a time. Let enough time go by (think days, not hours) before you take your question somewhere else. Sometimes people at another site may suggest you post here if your question doesn't fit within the scope of the other site.
Always link to your other posts, and update everywhere with any solution…