The following produces a 2 x 2 facetted plot, with different x and y ranges on each of the facets:
set.seed(1)
n = 4
x = runif(n)
y = runif(n)
df = data.frame(x,y)
cv = c(0,0.5,1)
df$facetx = letters[cut(df$x,cv)]
df$facety = letters[cut(df$y,cv)]
base = ggplot(data=df,aes(x,y)) +
geom_point() +
facet_grid(facetx~facety,scales='free')
base
Now I want to place a text / label on each of the facets, like so:
df.labs = expand.grid(facetx=c('a','b'),facety=c('a','b'));
df.labs$label = sprintf("Label %s",1:nrow(df.labs))
base +
geom_text(data = df.labs,x=0.5,y=0.5,aes(label=label))
How can I define the positioning of the text / label, so that it is PRECISELY some fraction of the distance along the facets, say at x = 0.75 an y = 0.75 (three-quarters horizontally, and three-quarters vertically).
In other words, I want it to be positioned relative to the facet viewport, not the values of the points rendered within the viewport.