1

I would like to plot something like this with ggplot2

enter image description here

I can do this:

library(ggplot2)
ggplot() + geom_hline(yintercept=1) + 
  ylab("Likelihood") + 
  theme(axis.ticks = element_blank(), axis.text.y = element_blank(), 
        panel.background = element_blank())

enter image description here

But I still need to add the line with -infinity 0 and infinity

aosmith
  • 34,856
  • 9
  • 84
  • 118
Ignacio
  • 7,646
  • 16
  • 60
  • 113
  • 2
    FYI in the development version of *ggplot2* you can add arrows onto axis lines. If you have an x axis you can use something like `axis.line.x = element_line(arrow = arrow(ends = "both"))` in `theme`. – aosmith Sep 13 '16 at 15:12

1 Answers1

1

Using a little help from this post, and a somewhat hacky solution, we can come up with something:

ggplot() + geom_hline(yintercept=1) + 
    ylab("Likelihood") + 
    xlab('')+
    theme(axis.ticks = element_blank(), axis.text.y = element_blank(), 
          panel.background = element_blank())+
    scale_x_continuous(breaks = c(-5,0,5),
                       labels = c(expression(-infinity), 0, expression(infinity)),
                       limits = c(-5,5))+
    geom_segment(aes(x = -Inf, xend = Inf, y = -1, yend = -1),
                 arrow = arrow(length = unit(.2, 'cm')))+
    geom_segment(aes(x = Inf, xend = -Inf, y = -1, yend = -1),
                 arrow = arrow(length = unit(.2, 'cm')))+
    ylim(c(-1,3))

enter image description here

Community
  • 1
  • 1
bouncyball
  • 10,631
  • 19
  • 31