Description Usage Arguments See Also Examples
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.
1 2 3 |
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 |
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 |
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()
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.