I'm making a study map with ggplot2, and would like to use a black star symbol like this ★ to plot city locations.
Is there a way to adjust the pch argument in geom_point to plot that symbol, maybe using a unicode expression? I've been successful at plotting other unicode symbols in ggplot2 with this code:
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(pch="\u2265", size=10)
When I use \u2605 instead for a black star symbol, the resulting plot just shows hollow rectangular symbols. Is there a different way to do this, or an alternative unicode for that symbol? I am using RStudio on my Mac if that makes a difference.
Thanks, Jay
The function geom_point() adds a layer of points to your plot, which creates a scatterplot.
Change point shapes, colors and sizes manually : The functions below can be used : scale_shape_manual() : to change point shapes. scale_color_manual() : to change point colors. scale_size_manual() : to change the size of points.
To color the points in a scatterplot using ggplot2, we can use colour argument inside geom_point with aes. The color can be passed in multiple ways, one such way is to name the particular color and the other way is to giving a range or using a variable.
You can use geom_text()
instead of geom_point()
and input directly a black star as the label (need to set family
to a font that supports the character)
ggplot(mtcars, aes(wt, mpg)) + geom_text(label="★", size=10, family = "HiraKakuPro-W3")
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(shape="\u2605", size=10, fill = "black")
The answer here may be just to set the shape
parameter to the unicode \u2605
.
Using a Mac here too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With