| Title: | Chernoff Faces for 'ggplot2' |
|---|---|
| Description: | Provides a Chernoff face geom for 'ggplot2'. Maps multivariate data to human-like faces. Inspired by Chernoff (1973) <doi:10.1080/01621459.1973.10482434>. |
| Authors: | David Selby [aut, cre] |
| Maintainer: | David Selby <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-05-17 05:55:04 UTC |
| Source: | https://github.com/selbosh/ggchernoff |
Uses Grid graphics to draw a face.
chernoffGrob( x = 0.5, y = 0.5, size = 1, colour = "black", fill = NA, alpha = 1, smile = 1, brow = NA, nose = FALSE, eyes = 1 )chernoffGrob( x = 0.5, y = 0.5, size = 1, colour = "black", fill = NA, alpha = 1, smile = 1, brow = NA, nose = FALSE, eyes = 1 )
x |
horizontal position |
y |
vertical position |
size |
area of the face |
colour |
colour of outlines and features |
fill |
fill colour |
alpha |
transparency, where 0 is transparent and 1 is opaque |
smile |
amount of smiling/frowning |
brow |
eyebrow angle, to represent anger or concern |
nose |
logical. Adds a nose to the face |
eyes |
distance between the eyes |
A grobTree object.
face <- chernoffGrob(.5, .5, size = 1e3, smile = -1, brow = 1, colour = 'navy', fill = 'lightblue') grid::grid.newpage() grid::grid.draw(face)face <- chernoffGrob(.5, .5, size = 1e3, smile = -1, brow = 1, colour = 'navy', fill = 'lightblue') grid::grid.newpage() grid::grid.draw(face)
The Chernoff geom is used to create data visualisations in the shape of human-like faces. By mapping to the relevant aesthetics, faces can appear to vary in happiness, anger, size, colour and so on.
geom_chernoff( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )geom_chernoff( mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
A Geom layer object for use with ggplot2.
geom_chernoff understands the following aesthetics (required aesthetics are in bold):
x
y
colour
fill
size
The following aesthetics are unique to geom_chernoff:
smile
brow
nose
eyes
For details, see chernoffGrob.
Chernoff, H. (1973). The use of faces to represent points in k-dimensional space graphically. Journal of the American Statistical Association, 68(342), 361–368.
library(ggplot2) ggplot(iris, aes(Sepal.Width, Sepal.Length, smile = Petal.Length, fill = Species)) + geom_chernoff() ggplot(data.frame(x = 1:4, y = c(3:1, 2.5), z = factor(1:4), w = rnorm(4), n = c(rep(FALSE, 3), TRUE) )) + aes(x, y, fill = z, size = x, nose = n, smile = w) + geom_chernoff()library(ggplot2) ggplot(iris, aes(Sepal.Width, Sepal.Length, smile = Petal.Length, fill = Species)) + geom_chernoff() ggplot(data.frame(x = 1:4, y = c(3:1, 2.5), z = factor(1:4), w = rnorm(4), n = c(rep(FALSE, 3), TRUE) )) + aes(x, y, fill = z, size = x, nose = n, smile = w) + geom_chernoff()
scale_brow lets you customise how eyebrows are generated from your data.
It also lets you tweak the appearance of legends and so on.
By default, brow is set to NA, in which case no eyebrows will appear (see Examples).
scale_brow_continuous(..., range = c(-1, 1), midpoint = mean) scale_brow(..., range = c(-1, 1), midpoint = mean)scale_brow_continuous(..., range = c(-1, 1), midpoint = mean) scale_brow(..., range = c(-1, 1), midpoint = mean)
... |
Other arguments passed onto |
range |
Output range of eyebrow angles. +1 corresponds to very angry and -1 corresponds to a worried look. |
midpoint |
A value or function of your data that will return level eyebrows, i.e. |
Use range to vary how angrily your maximum/minimum values are represented.
Minima smaller than -1 and maxima greater than +1 are possible but might look odd!
You can use midpoint to set a specific 'zero' value in your data or to have eyebrow angles represented as relative to average.
The function scale_brow is an alias of scale_brow_continuous.
At some point we might also want to design a scale_brow_discrete, scale_brow_manual and so on.
Legends are a work in progress. In particular, size mappings might produce odd results.
A Scale layer object for use with ggplot2.
library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, brow = Sepal.Length) + geom_chernoff() p p + scale_brow_continuous(midpoint = min) p + scale_brow_continuous(range = c(-.5, 2)) # Only show eyebrows if 'sad', otherwise hide them usa <- data.frame(date = c(time(presidents)), rating = c(presidents)) ggplot(subset(usa, complete.cases(usa))) + aes(date, rating, smile = rating, fill = rating, brow = ifelse(rating < 50, rating, NA)) + geom_line() + geom_chernoff(show.legend = FALSE) + scale_brow(range = -1:0) + scale_fill_gradient(low = 'skyblue1', high = 'goldenrod1')library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, brow = Sepal.Length) + geom_chernoff() p p + scale_brow_continuous(midpoint = min) p + scale_brow_continuous(range = c(-.5, 2)) # Only show eyebrows if 'sad', otherwise hide them usa <- data.frame(date = c(time(presidents)), rating = c(presidents)) ggplot(subset(usa, complete.cases(usa))) + aes(date, rating, smile = rating, fill = rating, brow = ifelse(rating < 50, rating, NA)) + geom_line() + geom_chernoff(show.legend = FALSE) + scale_brow(range = -1:0) + scale_fill_gradient(low = 'skyblue1', high = 'goldenrod1')
scale_eyes lets you customise how eye separation is determined from your data.
It also lets you tweak the appearance of legends and so on.
scale_eyes_continuous(..., range = c(0.1, 2), midpoint = mean) scale_eyes(..., range = c(0.1, 2), midpoint = mean)scale_eyes_continuous(..., range = c(0.1, 2), midpoint = mean) scale_eyes(..., range = c(0.1, 2), midpoint = mean)
... |
Other arguments passed onto |
range |
Output range of eye distances. 0 corresponds to a cyclops and +1 to a 'normal' distance. |
midpoint |
A value or function of your data that will return a 'normal' separation |
Use range to vary how happily/sadly your maximum/minimum values are represented.
Minima smaller than -1 and maxima greater than +1 are possible but might look odd!
You can use midpoint to set a specific 'zero' value in your data or to have eye width represented as relative to average.
The function scale_eyes is an alias of scale_eyes_continuous.
Legends are a work in progress. In particular, size mappings might produce odd results.
A Scale layer object for use with ggplot2.
geom_chernoff, scale_brow, scale_smile
library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, eyes = Sepal.Length) + geom_chernoff() p p + scale_eyes_continuous(midpoint = min) p + scale_eyes_continuous(range = c(0, 2))library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, eyes = Sepal.Length) + geom_chernoff() p p + scale_eyes_continuous(midpoint = min) p + scale_eyes_continuous(range = c(0, 2))
scale_smile lets you customise how smiles are generated from your data.
It also lets you tweak the appearance of legends and so on.
scale_smile_continuous(..., range = c(-1, 1), midpoint = mean) scale_smile(..., range = c(-1, 1), midpoint = mean)scale_smile_continuous(..., range = c(-1, 1), midpoint = mean) scale_smile(..., range = c(-1, 1), midpoint = mean)
... |
Other arguments passed onto |
range |
Output range of smiles. +1 corresponds to a full smile and -1 corresponds to a full frown. |
midpoint |
A value or function of your data that will return a neutral/straight face, i.e. |
Use range to vary how happily/sadly your maximum/minimum values are represented.
Minima smaller than -1 and maxima greater than +1 are possible but might look odd!
You can use midpoint to set a specific 'zero' value in your data or to have smiles represented as relative to average.
The function scale_smile is an alias of scale_smile_continuous.
At some point we might also want to design a scale_smile_discrete, scale_smile_manual and so on.
Legends are a work in progress. In particular, size mappings might produce odd results.
A Scale layer object for use with ggplot2.
library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, smile = Sepal.Length) + geom_chernoff() p p + scale_smile_continuous(midpoint = min) p + scale_smile_continuous(range = c(-.5, 2))library(ggplot2) p <- ggplot(iris) + aes(Sepal.Width, Sepal.Length, fill = Species, smile = Sepal.Length) + geom_chernoff() p p + scale_smile_continuous(midpoint = min) p + scale_smile_continuous(range = c(-.5, 2))