-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: support providing shapes as names rather than integers #2075
Comments
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 |
@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: |
Thanks Samer :) |
I have a few suggestions for improvements:
Putting all together: 0: open square |
This would be a pull request if someone else wanted to implement it. You'd need:
|
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. |
Agreed - I don't have the resources right now to do that systematically, but I will in the near future. |
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"... |
It depends how we want to treat the relation between the default shape set (which do not fill) and what the strings correspond to. |
To make people's lives easier, here goes the proposed correspondence between strings and shape numbers: library(ggplot2)
.pch_table <- c("0" = "open_square",
"1" = "open_circle",
"2" = "open_triangle",
"3" = "plus",
"4" = "cross",
"5" = "open_diamond",
"6" = "open_triangle_down",
"7" = "square_cross",
"8" = "asterisk",
"9" = "diamond_plus",
"10" = "circle_plus",
"11" = "star",
"12" = "square_plus",
"13" = "circle_cross",
"14" = "square_triangle",
"15" = "square",
"16" = "small_circle",
"17" = "triangle",
"18" = "diamond",
"19" = "circle",
"20" = "bullet",
"21" = "filled_circle",
"22" = "filled_square",
"23" = "filled_diamond",
"24" = "filled_triangle",
"25" = "filled_triangle_down")
df_shapes <- data.frame(shape = 0:25, shape_name = factor(paste0(0:25, " ('", .pch_table, "')")))
ggplot(df_shapes, aes(0, 0, shape = shape)) +
geom_point(aes(shape = shape), size = 5, fill = 'red', stroke = 2) +
scale_shape_identity() +
facet_wrap(~reorder(shape_name, shape)) +
theme_void() |
Nice. There is room for disagreement about the relative merits of |
I don't have a particular preference for The choice to use "filled" for symbols 21-25 and to use this as prefix rather than a suffix was based on the use in
|
Given that these are strings, I'd prefer |
Thanks for the input, everyone. Here goes the new names. I went with library(ggplot2)
pch_table <- c("0" = "square open",
"1" = "circle open",
"2" = "triangle open",
"3" = "plus",
"4" = "cross",
"5" = "diamond open",
"6" = "triangle down open",
"7" = "square cross",
"8" = "asterisk",
"9" = "diamond plus",
"10" = "circle plus",
"11" = "star",
"12" = "square plus",
"13" = "circle cross",
"14" = "square triangle",
"15" = "square",
"16" = "circle small",
"17" = "triangle",
"18" = "diamond",
"19" = "circle",
"20" = "bullet",
"21" = "circle filled",
"22" = "square filled",
"23" = "diamond filled",
"24" = "triangle filled",
"25" = "triangle down filled")
df_shapes <- data.frame(shape = 0:25, shape_name = factor(paste0(0:25, " ('", pch_table, "')")))
df_shapes <- df_shapes[order(pch_table),]
ggplot(df_shapes, aes(0, 0, shape = shape)) +
geom_point(aes(shape = shape), size = 5, fill = 'red', stroke = 2) +
scale_shape_identity() +
facet_wrap(~reorder(shape_name, shape)) +
theme_void()
sort(pch_table)
|
Can you please redo that plot alphabetically ordering the shapes? I think your code will be simpler if you flip the names and values. |
like this?
|
I meant just redraw the plot alphabetically. |
I'm getting warnings... but the output looks ok:
|
That's great, thanks! I wonder if |
Together with and
|
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:
I still like 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 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. |
@hadley the problem is that many shapes belong to more than one family (e.g. both triangle and square), |
@baptiste there's no reason for a shape to appear in only one place 😉 |
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. |
Can this issue be closed? It seems to me that this has been addressed with #2338. The following works for me. library(ggplot2)
mtcars$am2 <- ifelse(mtcars$am, "Manual", "Automatic")
ggplot(mtcars) + geom_point(aes(hp, cyl, shape = am2)) +
scale_shape_manual(values = c("Manual" = "triangle open", "Automatic" = "plus")) Created on 2018-05-11 by the reprex package (v0.2.0). |
Oops yes |
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/ |
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')
@thomasp85
The text was updated successfully, but these errors were encountered: