简体   繁体   中英

Define the fill of the zoomed panel using facet_zoom in ggforce

I want to fill the zoomed panel to match the default grey of facet_zoom in ggforce.

ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
   geom_point() +
   facet_zoom(x = Species == 'versicolor') +
   theme_bw()

在此处输入图像描述 I want the zoomed panel also to have the grey background. Any thoughts?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM