Reputation: 427
When trying to align the top left corner of the geom_label() box to the (0,10) coordinate with ggplot2, the text is not centered anymore (see picture). Is it possible to have a top left aligned box with centered text inside?
library(ggplot2)
data=data.frame(x=0:10,y=0:10)
ggplot(data,aes(x,y)) + geom_point() + geom_label(x=0,y=10,hjust=0,vjust=1,label="TEXT",size=8)
Upvotes: 3
Views: 649
Reputation: 24790
Here's an approach with geom_richtext
from the ggtext
package:
#install.packages("ggtext")
library(ggtext)
ggplot(data,aes(x,y)) +
geom_point() +
geom_richtext(x=0,y=10,hjust=0,vjust=1,label="TEXT",size=8,
label.padding = unit(c(0.25,0.25,0,0.25), "lines"))
Upvotes: 1