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
Request: support providing shapes as names rather than integers #2075
Currently if I want to use ggplot and make the points a certain shape, I need to say "shape=5" for example. Magic numbers like that are inconvenient: the author needs to figure iut what number means what shape, and the person reading the code has no idea what shape that'll be.
It'd be awesome to be able to say "geom_point (shape='diamond')
Suggestion (I don't have any strong opinion about the naming, just putting this out there so that others can improve on it or implement it):
0: square-open
1: circle-open
2: triangle-up-open
3: cross
4: x-mark (I didn't want to use simply "x" because currently using "x" or any other letter actually uses that letter)
5: diamond-open
6: triangle-down-open
7: square-x
8: asterisk
9: diamond-x
10: circle-cross
11: star
12: square-cross
13: circle-x
14: square-triangle
15: square
16: circle
17: triangle-up
18: diamond
19: circle (I can't figure out the difference between this and 16)
20: circle-small
21: circle-fill
22: square-fill
23: diamond-fill
24: triangle-up-fill
25: triangle-down-fill
@daattali, If I recall correctly, 16 & 19 can vary in appearance on some OSes depending on the underlying devices. e.g one of them may be aliased and the other not aliased.
from the documentation ggplot shapes are like pch base graphics parameter and in the pch help we have: The difference between pch = 16 and pch = 19 is that the latter uses a border and so is perceptibly larger when lwd is large relative to cex.
As the names will be specified as character strings, you may as well allow spaces for readability - otherwise perhaps use snake_case for general consistency with ggplot2 conventions.
Aim for consistency with the naming in ?pch, i.e. describe fill first, use same names for shapes. However, I like your suggestion to have some defaults to avoid long names - as well the default being a solid shape, I suggest assuming triangles are point up unless otherwise stated.
Use "plus" and "cross" vs "cross" and "x-mark": "plus" is unambiguous, "cross" can imply different shapes, but is often used for an x mark and works better for combinations of shapes.
If we think of 14 as a square with a chevron on top, we can have the convention that the closed shape always comes first (incidentally the orientation of the triangle comes out differently when I plot it from how it is in ?pch - different OS? different R version? Anyway, chevron works both ways).
Putting all together:
0: open square
1: open circle
2: open triangle
3: plus
4: cross
5: open diamond
6: open triangle down [or point down for consistency with ?pch]
7: square cross
8: asterisk
9: diamond plus
10: circle plus
11: star
12: square plus
13: circle cross
14: square chevron
15: square
16: small circle [as this is the one without the border, smaller than 1 and 19]
17: triangle
18: diamond
19: circle
20: bullet
21: filled circle
22: filled square
23: filled diamond
24: filled triangle
25: filled triangle down [or point down]
This could be a "good first issue" - now that GitHub is promoting this label to help potential first-time contributors discover issues, it would be good to see this being used in the R community. An accessible ggplot2 issue would be a good way to promote this.
I've implemented this so far with the strings from @hturner in snake case. Does anybody else have any suggestions/opinions on some of the strings such as "point down" vs simply "down", etc? "filled_triangle_point_down" feels like it's getting a bit lengthy to my eyes, so I've went with "down" for now.
symbols 21, 22, 23, 24, 25 are special in that they work with both fill and color, whereas the other symbols will ignore fill. Is there a case for making them a more convenient group of symbols to call? e.g. naming them simply "circle", "square", etc. without prefixing with "filled"...
Nice. There is room for disagreement about the relative merits of filled_circle and circle_filled or filled.circle or circle.filled. I was under the impression that x_y was more for functions, e.g. geom_boxplot while x.y was more for function arguments, e.g. outlier.shape. I could be wrong. Also there are situations where, say if you import a spreadsheet, a circle filled gets converted to circle.filled so possibly some benefits from having dots. I have no strong opinion. Personally I rarely use shapes outside of 21-26 and have them memorized.
I wonder if star should be triangle up down? And maybe it would be useful to have manually specified rows and columns? Then you could (e.g.) display the cross and plus variations in the matching columns. This would be useful to help people understand how the shapes are related to one another.
Having the modifiers as suffixes makes more sense to me when the shapes are ordered alphabetically. But this leads me to suggest a couple of changes:
"circle tiny" instead of "bullet"?
"nabla" instead of "triangle down"? (https://en.wikipedia.org/wiki/Nabla_symbol). This is a lot shorter to type and if you do sort the shapes alphabetically, the nablas will be separate from the triangles. Another way to separate the two types of triangle when sorting alphabetically would be to use "triangle rotated" but this is a lot longer, especially with the filled/open suffix.
I still like "star as it is short and describes the shape quite well. But "nabla triangle"/"triangle nabla" also works.
I think Hadley's last comment about the plot was to arrange so that the row represented the base shape and the column represented the modifier, e.g. the layout would be (shortened example)
@ptoche I mean a grid where you've carefully arranged the cells by hand so that related symbols appear next to each other. For example, in the previous plot, it would be nice if "triangle filled" and "triangle open" appeared on the far right to align with the filled and open shapes. Similarly, it would be nice if the all the unmodified shapes were arranged in one column. This would make it easier to see the underlying pattern in the shapes.
I think no matter how one puts it, these shapes are an odd bunch. Years ago I thought it would be nice to get a better set included in the low-level graphics primitives (more consistent, in terms of sizes, attributes, combinations, redundancy, etc.), but that seems unlikely nowadays; instead I hope that something like svg will soon become the only graphics format worth discussing, and all these 'device' quirks will be left behind.
Activity
daattali commentedon Mar 16, 2017
Suggestion (I don't have any strong opinion about the naming, just putting this out there so that others can improve on it or implement it):
0: square-open
1: circle-open
2: triangle-up-open
3: cross
4: x-mark (I didn't want to use simply "x" because currently using "x" or any other letter actually uses that letter)
5: diamond-open
6: triangle-down-open
7: square-x
8: asterisk
9: diamond-x
10: circle-cross
11: star
12: square-cross
13: circle-x
14: square-triangle
15: square
16: circle
17: triangle-up
18: diamond
19: circle (I can't figure out the difference between this and 16)
20: circle-small
21: circle-fill
22: square-fill
23: diamond-fill
24: triangle-up-fill
25: triangle-down-fill
has2k1 commentedon Mar 17, 2017
@daattali, If I recall correctly, 16 & 19 can vary in appearance on some OSes depending on the underlying devices. e.g one of them may be aliased and the other not aliased.
smouksassi commentedon Mar 17, 2017
from the documentation ggplot shapes are like pch base graphics parameter and in the pch help we have:
The difference between pch = 16 and pch = 19 is that the latter uses a border and so is perceptibly larger when lwd is large relative to cex.
daattali commentedon Mar 17, 2017
Thanks Samer :)
hturner commentedon Mar 17, 2017
I have a few suggestions for improvements:
Putting all together:
0: open square
1: open circle
2: open triangle
3: plus
4: cross
5: open diamond
6: open triangle down [or point down for consistency with ?pch]
7: square cross
8: asterisk
9: diamond plus
10: circle plus
11: star
12: square plus
13: circle cross
14: square chevron
15: square
16: small circle [as this is the one without the border, smaller than 1 and 19]
17: triangle
18: diamond
19: circle
20: bullet
21: filled circle
22: filled square
23: filled diamond
24: filled triangle
25: filled triangle down [or point down]
hadley commentedon Oct 30, 2017
This would be a pull request if someone else wanted to implement it. You'd need:
match.arg())geom_point()hturner commentedon Oct 31, 2017
This could be a "good first issue" - now that GitHub is promoting this label to help potential first-time contributors discover issues, it would be good to see this being used in the R community. An accessible ggplot2 issue would be a good way to promote this.
hadley commentedon Oct 31, 2017
Agreed - I don't have the resources right now to do that systematically, but I will in the near future.
daniel-barnett commentedon Nov 1, 2017
I've implemented this so far with the strings from @hturner in snake case. Does anybody else have any suggestions/opinions on some of the strings such as "point down" vs simply "down", etc? "filled_triangle_point_down" feels like it's getting a bit lengthy to my eyes, so I've went with "down" for now.
ptoche commentedon Nov 6, 2017
symbols 21, 22, 23, 24, 25 are special in that they work with both fill and color, whereas the other symbols will ignore fill. Is there a case for making them a more convenient group of symbols to call? e.g. naming them simply "circle", "square", etc. without prefixing with "filled"...
daniel-barnett commentedon Nov 9, 2017
It depends how we want to treat the relation between the default shape set (which do not fill) and what the strings correspond to.
daniel-barnett commentedon Nov 9, 2017
To make people's lives easier, here goes the proposed correspondence between strings and shape numbers:
ptoche commentedon Nov 10, 2017
Nice. There is room for disagreement about the relative merits of
filled_circleandcircle_filledorfilled.circleorcircle.filled. I was under the impression thatx_ywas more for functions, e.g.geom_boxplotwhilex.ywas more for function arguments, e.g.outlier.shape. I could be wrong. Also there are situations where, say if you import a spreadsheet, acircle filledgets converted tocircle.filledso possibly some benefits from having dots. I have no strong opinion. Personally I rarely use shapes outside of 21-26 and have them memorized.7 remaining items
hadley commentedon Nov 15, 2017
That's great, thanks!
I wonder if
starshould betriangle up down? And maybe it would be useful to have manually specified rows and columns? Then you could (e.g.) display the cross and plus variations in the matching columns. This would be useful to help people understand how the shapes are related to one another.ptoche commentedon Nov 16, 2017
Together with
"triangle down up" <- "triangle up down"?and
ptoche commentedon Nov 16, 2017
do you mean a grid like this one?
or basic shapes along both directions for a triangular matrix effect?
hturner commentedon Nov 16, 2017
Having the modifiers as suffixes makes more sense to me when the shapes are ordered alphabetically. But this leads me to suggest a couple of changes:
"circle tiny"instead of"bullet"?"nabla"instead of"triangle down"? (https://en.wikipedia.org/wiki/Nabla_symbol). This is a lot shorter to type and if you do sort the shapes alphabetically, the nablas will be separate from the triangles. Another way to separate the two types of triangle when sorting alphabetically would be to use"triangle rotated"but this is a lot longer, especially with the filled/open suffix.I still like
"staras it is short and describes the shape quite well. But"nabla triangle"/"triangle nabla"also works.I think Hadley's last comment about the plot was to arrange so that the row represented the base shape and the column represented the modifier, e.g. the layout would be (shortened example)
In which case alphabetical ordering is less important, but having a one-word name for the base shape is quite useful.
ptoche commentedon Nov 16, 2017
"circle tiny"is more consistent with the naming conventionshape+qualifier. By this reasoning,"triangle down"works better than"nabla".hadley commentedon Nov 16, 2017
@ptoche I mean a grid where you've carefully arranged the cells by hand so that related symbols appear next to each other. For example, in the previous plot, it would be nice if "triangle filled" and "triangle open" appeared on the far right to align with the filled and open shapes. Similarly, it would be nice if the all the unmodified shapes were arranged in one column. This would make it easier to see the underlying pattern in the shapes.
baptiste commentedon Nov 27, 2017
@hadley the problem is that many shapes belong to more than one family (e.g. both triangle and square),
hadley commentedon Nov 28, 2017
@baptiste there's no reason for a shape to appear in only one place 😉
baptiste commentedon Nov 28, 2017
There we go again with quantum Venn diagrams ;)
I think no matter how one puts it, these shapes are an odd bunch. Years ago I thought it would be nice to get a better set included in the low-level graphics primitives (more consistent, in terms of sizes, attributes, combinations, redundancy, etc.), but that seems unlikely nowadays; instead I hope that something like svg will soon become the only graphics format worth discussing, and all these 'device' quirks will be left behind.
clauswilke commentedon May 12, 2018
Can this issue be closed? It seems to me that this has been addressed with #2338. The following works for me.
Created on 2018-05-11 by the reprex package (v0.2.0).
hadley commentedon May 12, 2018
Oops yes
lock commentedon Nov 8, 2018
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/