Last active
February 22, 2020 15:07
-
-
Save gkaramanis/7d22ae6adba5553092884cd9513bfd31 to your computer and use it in GitHub Desktop.
Add "background" to axis title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(grid) | |
myGrob <- grobTree(rectGrob(gp = gpar(fill = "purple", alpha = 0.5))) | |
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + | |
geom_point() + | |
annotation_custom(myGrob, xmin = -10, xmax = -1, ymin = -10, ymax = Inf) + # x axis | |
annotation_custom(myGrob, xmin = -10, xmax = Inf, ymin = -10, ymax = -1) + # y axis | |
coord_cartesian(xlim = c(0, 10), ylim = c(0, 10), clip = "off") + | |
theme( | |
plot.margin = margin(0, 0, 100, 100) | |
) + | |
ggsave("~/Desktop/axis-bg.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment