knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ggplot2)
library(emphatic)
library(ggplot2)
library(emphatic)

Goal

Use {emphatic} to highlight the mtcars dataset where:

Step 1: mtcars

mtcars

Step 2: Use {emphatic}

mtcars |>
  hl('skyblue')

Step 3: Highlight only rows where cylinder is 6 or 8

mtcars |>
  hl('skyblue', rows = cyl %in% c(6, 8))

Step 4: Shade by mpg rating using ggplot2::scale_colour_viridis_c()

mtcars |>
  hl(ggplot2::scale_colour_viridis_c(), rows = cyl %in% c(6, 8), cols = mpg)

Step 5: Extend shading across all rows except gear and carb

mtcars |>
  hl(ggplot2::scale_colour_viridis_c(), rows = cyl %in% c(6, 8), cols = mpg, scale_apply = mpg:am)

Step 6: Highlight the maximum mpg

mtcars |>
  hl(ggplot2::scale_colour_viridis_c(), rows = cyl %in% c(6, 8), 
     cols = mpg, scale_apply = mpg:am) |>
  hl('hotpink', rows = mpg == max(mpg))

Step 7: De-emphasise the text

mtcars |>
  hl(ggplot2::scale_colour_viridis_c(), rows = cyl %in% c(6, 8), 
     cols = mpg, scale_apply = mpg:am) |>
  hl('hotpink', rows = mpg == max(mpg)) |>
  hl_adjust(text_contrast = 0.25)


coolbutuseless/emphatic documentation built on Dec. 27, 2024, 1:18 a.m.