You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow point shapes to be mixtures of names and symbols #5088
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.)
you can write your own version of 'translate_shape_string' for example I wrote mine that has:
....
"blank" = NA
so I can turn the point off like we can turn the line off with linetype = "blank"
I agree, writing such a function is probably what I will do! I wonder whether other users of ggplot2 might also like to do something like this. I think this is especially true of pch=46 (the dot) because I believe it is special: if you use 'circle' or 'a' as a point marker then it grows with size, but I believe that pch=46 is always a single pixel, which I end up using fairly often for that reason. So for me a mixture of circles and single pixels is not unusual.
I think the mixed used of translatable, e.g. 'circle', and verbatim, e.g. '.', '?', 'a' etc. is a bit problematic as the former converts to the integer representation of shapes, whereas the latter stays a character, which are difficult to mix in a single vector. I could see some benefit in adding 'dot' and 'blank' to the translation list though.
After trying out an implementation, we've decided against using names and symbols. The main reason for this is that it is not idiomatic for the grammar of graphics. See discussion in #5143.
Activity
smouksassi commentedon Dec 6, 2022
you can write your own version of 'translate_shape_string' for example I wrote mine that has:
....
"blank" = NA
so I can turn the point off like we can turn the line off with linetype = "blank"
in your case, you can add
....
"dot" = 46
banbh commentedon Dec 6, 2022
I agree, writing such a function is probably what I will do! I wonder whether other users of
ggplot2might also like to do something like this. I think this is especially true ofpch=46(the dot) because I believe it is special: if you use 'circle' or 'a' as a point marker then it grows with size, but I believe thatpch=46is always a single pixel, which I end up using fairly often for that reason. So for me a mixture of circles and single pixels is not unusual.teunbrand commentedon Dec 24, 2022
I think the mixed used of translatable, e.g. 'circle', and verbatim, e.g. '.', '?', 'a' etc. is a bit problematic as the former converts to the integer representation of shapes, whereas the latter stays a character, which are difficult to mix in a single vector. I could see some benefit in adding 'dot' and 'blank' to the translation list though.
teunbrand commentedon Mar 22, 2023
After trying out an implementation, we've decided against using names and symbols. The main reason for this is that it is not idiomatic for the grammar of graphics. See discussion in #5143.