-2

Is there a way to add a horizontal line to a boxplot in ggplot2, that doesn't cut through the existing plot, but only the spaces in between?

Thanks for your help...

ChrM
  • 61
  • 3
  • 12
  • 3
    You could improve your question. Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve it accordingly. A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session. – lukeA Nov 22 '16 at 14:09
  • 1
    You are absolutely right, that my question is a bit rudimentary. But time was of the essence in this case and I was sure that you guys would get my Problem (which you apparently did). Still, I'm going to provide a bit more Input the next time. – ChrM Nov 22 '16 at 14:18

1 Answers1

1

ggplot adds up each geom one after another, so...

library(ggplot2)
df <- data.frame(x = gl(3,1), y = 1:3)
ggplot(df, aes(x,y)) + 
  geom_hline(yintercept = 1.5) + 
  geom_col(width = .5)

... places a horizontal line under the bars produced by geom_col.

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • 4
    Your answer is good, and so was your comment. Something I've been thinking about lately (probably better for meta), is it disingenuous to suggest the OP to improve their question, but still answer the question? If we still answer poorly composed questions doesn't that make improving the question somewhat ancillary? – bouncyball Nov 22 '16 at 14:12
  • 1
    Very good point, and I agree. In this case here (and some others in the past) I found it to be friendlier to a.) immediately provide a solution to an obvious problem and b.) ask the rather new OP to follow standards, so that every visitor gets the most out of questions and answers. With regards to her/his comment, it worked. :) But, as I said, in general I agree. – lukeA Nov 22 '16 at 14:42