Thraupidae Thraupidae - 2 months ago 26
R Question

Corner Labels in ggplot2

I'm interested in trying to create simple corner labels for a multipanel figure I am preparing in ggplot. This is similar to this previously asked question, but the answers only explained how to include a label at the top of the plot, not produce a corner label in the format required by many journals. I hope to replicate something similar to the

plotrix
function
corner.label()
in
ggplot2
.

Here is an example using
plottrix
of what I would like to recreate in
ggplot2
.

require(plotrix)

foo1<-rnorm(50,25,5)
foo2<-rpois(50,25)
foo3<-rbinom(50,25,0.5)
foo4<-rnbinom(50,25,0.5)

par(mfrow=c(2,2))
hist(foo1)
corner.label(label='a',figcorner=T)
hist(foo2)
corner.label(label='b',figcorner=T)
hist(foo3)
corner.label(label='c',figcorner=T)
hist(foo4)
corner.label(label='d',figcorner=T)


This produces the following:

enter image description here

Thanks for any help in advance!

Answer

An example:

d <- data.frame(x = runif(16),
                y = runif(16),
                grp = rep(letters[1:4],each = 4))

ggplot(d,aes(x = x,y = y)) + 
facet_wrap(~grp) + 
geom_point() + 
theme(strip.text = element_text(hjust = -0.05),
      strip.background = element_blank())

enter image description here