teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
564 stars 33 forks source link

Partial rectangle theme element #13

Closed teunbrand closed 4 years ago

teunbrand commented 4 years ago

If you want a to have a line at some place, but not a full rectangle; it would make sense to me that it would be possible to implement something like element_part_rect(side = "tlbr", fill = NA, colour = "black"). The side argument (abbrevated: top, left, bottom, right) would control where the lines would go.

Inspiration here: https://github.com/wilkelab/ggtext/blob/master/R/element-textbox.R

Notes:

teunbrand commented 4 years ago

Now works pretty OK.

library(ggplot2)
library(ggh4x)

ggplot(mpg, aes(displ, cty)) + geom_point() +
    facet_grid(cols = vars(year, cyl)) +
    theme(
        strip.background = element_part_rect(side = "b", colour = "magenta",
                                             fill = NA),
        panel.border = element_part_rect(side = "rt", colour = "black",
                                         linetype = 2, fill = NA)
    )

Created on 2020-06-02 by the reprex package (v0.3.0)

wbvguo commented 10 months ago

Hi, thanks for maintaining this tool.

Can we use different panel border line type for different layer of facet? for example, in the facet_nested, if we set the outer facet layer as year and the inner facet layer as cyl. Can we set the outer facet panel border line to be solid line, and set the inner facet panel border line to be the dashed line?

Thanks, Wenbin

teunbrand commented 10 months ago

Yes you could essentially follow this part of the vignette and use a list of element_part_rect() for the background.