Ignacio - 1 year ago 80

R Question

I would like to plot something like this with ggplot2

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())

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

Answer Source

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))
```