map_colour_text: Modifies a data frame to determine color to overlay on a...

Description Usage Arguments See Also Examples

Description

Takes a data frame with a value to map to a fill colour and determines whether light or dark text should be used as the label on top of the fill. For use with ggplot2::scale_colour_identity() downstream.

Usage

1
2
3
map_colour_text(df, bckgrnd_column, colour_palette,
  limits = c(min(df[[bckgrnd_column]]), max(df[[bckgrnd_column]])),
  sat_threshold = 0.5, dark_colour = grey90K, light_colour = "white")

Arguments

df

data frame containing the data

bckgrnd_column

string containing the name of the column to map to fill values

colour_palette

colour palette specification (list of hex values). Can use RColorBrewer::brewer.pal to generate

limits

(optional) limits for the fill color palette mapping

sat_threshold

(optional) breakpoint between the light and dark text color. 50 percent saturation, by default

dark_colour

(optional) dark color to overlay on low fill values

light_colour

(optional) light color to overlay on high fill values

See Also

scale_colour_text

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{
# Define a Color Brewer palette
library(RColorBrewer)
# Generate random data
df = data.frame(x = 1:9, y = 1:9)
pal = 'Reds'

limits = c(0,15)
df = map_colour_text(df, 'x',  brewer.pal(9, pal), limits)

library(ggplot2)
ggplot(df, aes(x = x, y = y, fill = x, colour = text_colour, label = round(hsv.s,2))) +
geom_point(size = 10, shape = 21) + 
geom_text() +
scale_fill_gradientn(colours = brewer.pal(9, pal), limits = limits) +
scale_colour_identity() +
theme_blank()
}

flaneuse/llamar documentation built on May 16, 2019, 1:18 p.m.