2

R version 3.1.1 (2014-07-10) Platform: i386-w64-mingw32/i386 (32-bit)

I am working on a histogram with ggplot2. Since I have heavily tailed data, I would like to use axis "clip marks" at the end of the x-axis in ggplot like in the following example. (not the red 0.95 quantile but the small black clip marks at the end of the x axis)

The question is not about a break within the axis as asked in Using ggplot2, can I insert a break in the axis? but about clipping of the end of the axis and adding a marker, that the reader of the plot can immediately see, that the observed data exceeds the axis. This example has two little tilted parallel slashes at the end of the x-axis. This is what I would like to achieve on a ggplot plot.

require(plotrix)
x <- rbeta(10000, 1, 7)
hist(x, xlim=c(0,0.4))
axis.break(1,0.405)

enter image description here

Is there a possibility to get similar axis break marks with ggplot? I had the idea to work with geom_segment but I did not achieve any good solution, since it always depends on the ratio of the x and y axis values.

ggplot()+
      geom_histogram(aes(x=x), binwidth = 0.05)+
      coord_cartesian(xlim = c(0, 0.45))

Thanks for your help!

Community
  • 1
  • 1
VDK
  • 789
  • 8
  • 15
  • look at `geom_vline` – Davide Passaretti May 19 '15 at 09:48
  • @Davide Passaretti The question is not about the red line but the small break marks at the end of the x axis. – VDK May 19 '15 at 09:55
  • This [answer](http://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis) suggests it cannot be done. They also suggests other alternatives (e.g. log axis). – ddiez May 19 '15 at 10:10
  • @ddiez The question is not about a break within the axis as asked in ["Using ggplot2, can I insert a break in the axis?"](http://stackoverflow.com/questions/7194688/using-ggplot2-can-i-insert-a-break-in-the-axis) but about cutting of the end of the axis and add a marker that the reader of the plot can immediately see, that data has been clipped off. – VDK May 19 '15 at 10:49
  • Ah ok, understood now. I would suggest you change the plot because it is very misleading (that is, it contains a break in the axis and there are values beyond the red mark). Anyway, someone wrote an answer- hopefully is what you were looking for. – ddiez May 19 '15 at 13:02
  • On a second thought, maybe i still don't understand. Do you want the red line or the little break marks in the axis? – ddiez May 19 '15 at 13:05
  • I edited the question. It should be clear now. Sorry for the trouble. – VDK May 19 '15 at 13:09

1 Answers1

2

EDIT after comment. Better?

ggplot()+  geom_histogram(aes(x=x), binwidth = 0.05, color = "grey30", fill = "white")+
  coord_cartesian(xlim = c(0, 0.405)) +
  theme_tufte() +
  labs(y = "Frequency") +
  annotate("text", x = 0.4, xend = 0.4, y = 0.01, yend = .99, colour = "red", label = "//", size =6) 

enter image description here

lawyeR
  • 7,488
  • 5
  • 33
  • 63
  • That is not, what I was looking for. I edited the question. Now it should be clear. Sorry. – VDK May 19 '15 at 13:10
  • Actually a good and creative idea. I will try to implement it to my purpose. – VDK May 19 '15 at 17:25
  • Glad to help, even if I am slow to understand what you wanted. :) Possibly consider accepting the answer unless a better one comes along. – lawyeR May 19 '15 at 18:28
  • Did it. My mistake, question was formulated not very well by me. – VDK May 24 '15 at 10:51