1

I'm plotting a histogram using geom_histogram:

ggplot(middle_single, aes(clustersize)) + geom_histogram(binwidth = 100, drop=TRUE)   +scale_y_log10(limits=c(0.1,100)) 

But it shows negative values for the bins with zero counts (log of 0 is negative inf), but I want to remove them from my graph. How can I do that? enter image description here

I checked many questions on the web, but non of them actually solve my problem (Histogram with "negative" logarithmic scale in R and How to suppress zeroes when using geom_histogram with scale_y_log10)

Alex
  • 1,914
  • 6
  • 26
  • 47

2 Answers2

0

Perhaps trim them from your data?

trimmed_data <- middle_single[middle_single$clustersize >=0,]

Then plot?

Darren
  • 333
  • 2
  • 10
0

I could find one solution to this, in this reply by Ganesh Shastry on this other question: https://stackoverflow.com/a/63522382/4563445. Using the following:

scale_y_log10(oob = scales::squish_infinite) +

The warning message remains, but the plot is repaired!