element_textbox_highlight: Highlight the facet using different color and background...

Description Usage Arguments Examples

View source: R/facet_highlight.R

Description

Highlight the facet using different color and background powered by ggtext package

forked from https://stackoverflow.com/questions/60332202/conditionally-fill-ggtext-text-boxes-in-facet-wrap

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
element_textbox_highlight(
  ...,
  hi.labels = NULL,
  hi.fill = NULL,
  hi.col = NULL,
  hi.box.col = NULL,
  hi.labels2 = NULL,
  hi.fill2 = NULL,
  hi.col2 = NULL,
  hi.box.col2 = NULL
)

Arguments

...

other paras

hi.labels

which facet to be highlight

hi.fill

the color of the background

hi.col

the color of the text

hi.box.col

the color of the box

hi.labels2

which facet to be highlight 2

hi.fill2

the color of the background 2

hi.col2

the color of the text 2

hi.box.col2

the color of the box 2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(ggplot2)
ggplot(mpg, aes(cty, hwy)) +
geom_point() +
  facet_wrap(~class) +
  ggtheme::theme_pub() +
  theme(
    strip.background = element_blank(),
    strip.text = element_textbox_highlight(
      size = 12, face = "bold",
      # unnamed set (all facet windows except named sets below)
      color = "white", fill = "#5D729D", box.color = "#4A618C",
      halign = 0.5, linetype = 1, r = unit(5, "pt"), width = unit(1, "npc"),
      padding = margin(5, 0, 3, 0), margin = margin(3, 3, 3, 3),
      # this is new relative to element_textbox():
      # first named set
      hi.labels = c("minivan", "suv"),
      hi.fill = "#F89096", hi.box.col = "#A6424A", hi.col = "black",
      # add second named set
      hi.labels2 = c("compact", "pickup"),
      hi.fill2 = "green", hi.box.col2 = "#A6424A", hi.col2 = "black"
   )
  )

  ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() + facet_grid(~Species) +
  theme(
    strip.background = element_blank(),
    strip.text = element_textbox_highlight(
      size = 12, face = "bold",
      # unnamed set (all facet windows except named sets below)
      color = "white", fill = "#5D729D", box.color = "#4A618C",
      halign = 0.5, linetype = 1, r = unit(5, "pt"), width = unit(1, "npc"),
      padding = margin(5, 0, 3, 0), margin = margin(3, 3, 3, 3),
      # this is new relative to element_textbox():
      # first named set
     hi.labels = c("versicolor"),
      hi.fill = "#F89096", hi.box.col = "#A6424A", hi.col = "black",
      # add second named set
      hi.labels2 = c("virginica"),
      hi.fill2 = "green", hi.box.col2 = "#A6424A", hi.col2 = "black"
    )
  )

ZhonghuiGai/ggfacet documentation built on Dec. 18, 2021, 8:28 p.m.