I'd like to specify my own shape palettes for ggplot2
at least as a vector for input into scale_shape_manual
. I really like the paired shapes palette from JMP, but noticed R doesn't have some of these shapes. In particular, sideways triangles (e.g. |>
or <|
) or a filled upside down triangle (e.g. \/
) are missing. Are these available anywhere? If not, how can I specify these extra shapes and is there a way to get ggplot2
to use them in plots?
Asked
Active
Viewed 3,684 times
5
1 Answers
21
You can create your own shape palette by specifying the Unicode values for the characters you want. You can find Unicode values for various geometric shapes here. For example:
library(ggplot2)
ggplot(mtcars[mtcars$carb %in% 1:4,],
aes(wt, mpg, shape=factor(carb), colour=factor(carb))) +
geom_point(size=5) +
scale_shape_manual(values=c("\u25BA","\u25C4","\u25BC","\u25B2"))
You can, of course, use Unicode characters in base graphics as well:
with(mtcars, plot(wt, mpg, pch="\u25BC"))
Not every Unicode character renders correctly. I'm not sure why, but it may have to do with which fonts you have installed.

eipi10
- 91,525
- 24
- 209
- 285
-
2Relatedly, I have found two packages to help with special symbols, fonts and emojis: https://cran.r-project.org/web/packages/emojifont/vignettes/emojifont.html (author Y.X. Qiu) and https://github.com/dill/emoGG/issues (author D.L.Miller) – PatrickT May 08 '16 at 19:46
-
I just noticed that, on my system, the red and green symbols don't appear in the ``R`` console (and don't get printed in the PDF), while they do appear in the ``RStudio`` console, but none of the 4 symbols get printed, even with ``cairo_pdf`` or ``cairo_ps`` devices... only option so far is to print as PNG. – PatrickT May 08 '16 at 20:20
-
2@PatrickT I've noticed this also. In some cases, you can get the symbols to appear by specifying a different font face. [Here's an example](http://stackoverflow.com/a/34083063/496488) where I did that. The [`extrafont` package](https://github.com/wch/extrafont/) is useful for adding new fonts. – eipi10 Dec 08 '16 at 05:25
-
Thanks eipi10, very useful! – PatrickT Dec 08 '16 at 12:38