I didn't want to modify facet_zoom
and I was hoping someone might know of an elegant way to modify the color of the zoom panels like with zoom.x = element_rect(fill = "grey", color = NA), zoom.y = element_rect(fill = "grey", color = NA)
within theme
, but those only address the zoomed section of the un-zoomed panel and the callout to the zoomed panel. I do have a more brute force way to do it using annotate
:
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
annotate("rect", xmin = data.table(iris)[Species == 'versicolor', min(Petal.Length)] * 0.965, xmax = data.table(iris)[Species == 'versicolor', max(Petal.Length)] * 1.02, ymin = -Inf, ymax = Inf, fill="light grey", alpha=0.3) +
geom_point() +
facet_zoom(x = Species == 'versicolor') +
theme_bw()
The challenge to to find the boundaries of the x and/or y axis when they're not explicit in facet_zoom
. I had to hunt and peck to get them to align.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.