Skip to content

Allow point shapes to be mixtures of names and symbols #5088

Closed as not planned

Description

@banbh

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.)

Activity

  1. smouksassi commented on Dec 6, 2022

    @smouksassi

    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

  2. banbh commented on Dec 6, 2022

    @banbh
    Author

    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.

  3. added
    feature
    on Dec 24, 2022
  4. teunbrand commented on Dec 24, 2022

    @teunbrand
    Collaborator

    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.

  5. teunbrand commented on Mar 22, 2023

    @teunbrand
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions