I have a two facet plots created in ggplot2. I would like to add an arrow outside of the plot area. Multiple questions tried to address this: How to draw lines outside of plot area in ggplot2? Displaying text below the plot generated by ggplot2
but I can't make my example work. Also, I hope there is an easier way to accomplish this?
I tried to increase plot.margins
and to use coord_cartesian()
, but neither helped.
Instead, I want:
My dummy example:
# read library to assess free data
library(reshape2)
library(ggplot2)
ggplot(tips,
aes(x=total_bill,
y=tip/total_bill)) +
geom_point(shape=1) +
facet_grid(. ~ sex) +
# define the segment outside the plot
geom_segment(aes(x = 10,
y = -0.25,
xend = 10,
yend = 0),
col = "red",
arrow = arrow(length = unit(0.3, "cm"))) +
theme_bw() +
# limit the displayed plot extent
coord_cartesian(ylim = c(0, 0.75)) +
# increase plot margins - does not help
theme(plot.margin = unit(c(1,1,1,0), "lines"))