-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Point shapes can be specified by supplying numerical codes. For example:
# Works, but shape is cryptic:
ggplot(tibble(x = c('.', 'circle'),
shape = c(46, 19))) +
geom_point(aes(x, x, shape = shape)) +
scale_shape_identity() It would nice to specify the shape using a name as follows:
# Uses "c" as shape for second point:
ggplot(tibble(x = c('.','circle'))) +
geom_point(aes(x, x, shape = x)) +
scale_shape_identity()
# Generates error:
ggplot(tibble(x = c('circle','.'))) +
geom_point(aes(x, x, shape = x)) +
scale_shape_identity()However, the first snippet treats "circle" as "c" (and hence uses the letter "c" as the plot shape) while the second snippet generates an error.
The problem is that the plotting code (https://github.com/tidyverse/ggplot2/blob/main/R/geom-point.r#L146) wants the entire vector of shapes to be either single latter symbols or longer labels, as opposed to a mixture. Furthermore, it decides which is the case based on the first item in the vector of shapes. Would it be possible to look up shape names in pch_table for those names with nchars() > 1 and convert the rest to their ascii code? (I suppose there may be issues with non-ascii but single letter shapes.)