Styles

library(gglite)
df = data.frame(x = c('A', 'B', 'C'), y = c(3, 7, 2))
p  = g2(df, y ~ x)

Use style_mark() to set visual properties on the most recently added mark. The following bar chart in its default style is used as the baseline for the bar examples below.

p

1 Custom Fill on Bars

p |> style_mark(fill = 'tomato', stroke = '#333', lineWidth = 3)

2 Custom Fill and Stroke on Points

g2(mtcars, hp ~ mpg) |>
  style_mark(fill = 'orange', stroke = '#333', lineWidth = 3)

3 Semi-Transparent Area

df_line = data.frame(x = 1:10, y = c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3))
p_area = g2(df_line, y ~ x) |> mark_area()
p_area |> style_mark(fill = 'steelblue', fillOpacity = 0.3)

4 Line with Custom Stroke

p_line = g2(df_line, y ~ x) |> mark_line()
p_line |> style_mark(stroke = 'tomato', lineWidth = 3)

5 Dashed Line

p_line |> style_mark(stroke = 'steelblue', lineDash = c(6, 3))