Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

black star symbol for geom_point in ggplot2

Tags:

r

unicode

ggplot2

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

like image 495
Jason Avatar asked Jan 06 '16 15:01

Jason


People also ask

What does geom_point () do in R?

The function geom_point() adds a layer of points to your plot, which creates a scatterplot.

How do I change the shape of a point in ggplot2?

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.

How do I change the color of a geom point?

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.


2 Answers

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

like image 75
Jerry Chi Avatar answered Oct 01 '22 17:10

Jerry Chi


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.

like image 38
Rômulo Barros Avatar answered Oct 01 '22 15:10

Rômulo Barros