I am labeling points in a regression and want to "mask" the labels so they are easy to read when they intersect the line. ArcGIS has a function for this called masking. Simple masking is essentially adding a white background (or shadow/mask) to text. I have looked over the ggplot text documentation and it seems the ggplot way of fixing this would be to use geom_label, but I find that a bit clunky looking. I am trying to make the area I highlighted with red pen on
look a bit nicer.
Sample:
ggplot(mtcars[1:10,], aes(wt, mpg)) +
geom_point() +
stat_smooth(method="lm", se=FALSE, color="black") +
geom_text(aes(label=rownames(mtcars)[1:10]),hjust=.5, vjust=-.4)#mask text?
Solution:
ggplot(mtcars[1:10,], aes(wt, mpg)) +
geom_point() +
stat_smooth(method="lm", se=FALSE, color="black") +
geom_shadowtext(aes(label=rownames(mtcars)[1:10]),hjust=.5, vjust=-.4,
col="black", bg.color="white", cex=4, r=2)