3

I am plotting a histogram with ggplot2 via rpy2 as follows:

p = ggplot2.ggplot(df) + \
    ggplot2.aes_string(x="x", colour="sample") + \
    ggplot2.facet_grid(Formula("sample ~ .")) + \
    ggplot2.geom_histogram(binwidth=0.3, fill="white")

It works great, except that geom_histogram, like geom_density, adds a "base line" bar at the bottom of the histogram that I would like to remove. How can this line be removed? Here's a picture of the line I am referring to annotated with an arrow. thanks. enter image description here

  • this is an R question not rpy2! generally you if you get the feature in R , the translation to rpy2 is straight.. – agstudy Feb 18 '13 at 15:14
  • 4
    Try `drop = TRUE`, and see the docs for `stat_bin` – hadley Feb 18 '13 at 16:24
  • @hadley recent versions of ggplot2 say that drop is deprecated – Adrian Feb 09 '17 at 16:21
  • Same issue comes up in the comments at http://stackoverflow.com/questions/23083819/how-to-suppress-zeroes-when-using-geom-histogram-with-scale-y-log10: Currently, geom_histogram says: “drop is deprecated. Please use pad instead.” But pad=TRUE doesn’t do the same thing. – Adrian Feb 09 '17 at 16:24
  • 1
    Instead of `drop=TRUE` or `pad=TRUE` one can hide the base line by covering it with a white line, add the following to the call: `+ geom_hline(yintercept=0, colour="white", size=.25)` – Marjolein Fokkema Mar 19 '22 at 16:31

1 Answers1

1

That's coming from the edge of the bar.

Just remove colour = "sample".

lgautier
  • 11,363
  • 29
  • 42
  • thanks, but I do want the histograms coloured by `sample` though, I just don't want the line. I think @hadley's solution does the trick –  Feb 19 '13 at 22:37
  • 1
    @user248237 : if only one person has the answer to your question, that'd be Hadley. – lgautier Feb 20 '13 at 16:15