Custom shape in ggplot (geom_point)
Asked Answered
M

1

11

Aim

I am trying to change the shape of the geom_point into a cross (so not a "plus/addition" sign, but a 'death' cross).

Attempt

Let say I have the following data:

library(tidyverse)

df <- read.table(text="x y
                 1    3 
                 2    4 
                 3    6 
                 4    7 ", header=TRUE) 

I am able to change the shape using the shape parameter in geom_point into different shapes, like this:

ggplot(data = df, aes(x =x, y=y)) +  
   geom_point(shape=2)   # change shape

However, there is no option to change the shape into a cross.

Question

How do I change the shape of a value into a cross using ggplot in R?

Mores answered 21/2, 2019 at 9:43 Comment(2)
Try shape = 4Drogin
you can refer sape.inf.usi.ch/quick-reference/ggplot2/shape for all shapes availableEhling
B
28

Shape can be set to a unicode character. The below uses the skull and crossbones but you can look up a more suitable symbol.

Note that the final result will depend on the font used to generate the plot.

ggplot(data = df, aes(x =x, y=y)) +  
  geom_point(shape="\u2620", size = 10) 

Bialystok answered 21/2, 2019 at 10:55 Comment(2)
"\u2020" was exactly what I was looking for!Mores
Here or here is a list of other choices.Coloratura

© 2022 - 2024 — McMap. All rights reserved.