26 types of point shapes in R

In this article, we will review the 26 types of point shapes that we can draw in base R and the ggplot2 package. The shape codes range from 0 to 25 and the default symbol is equal to 19:

26 different point shapes in base R (top) and ggplot2 (bottom)

Comparison of parameters

To begin, the point types can be customized using the following parameters:

ParametersIn base RIn ggplot2
point character / symbolpchshape
character expansion / extensioncexsize
line width (not for symbols between 15 and 18 in base R)lwdstroke
colorcolcol / color / colour
background (not for symbols between 0 and 20)bgfill

Dataframe used for the following plots

Moreover, I used the code below to create the dataframe to draw each symbol in base R and ggplot2:

df = data.frame(x = c(seq(1, 5), seq (1, 5), seq(1, 5), seq(1, 6), seq(1, 5)),
                y = c(rep(5, 5), rep (4, 5), rep(3, 5), rep(2, 6), rep(1, 5)))

Available point shapes in base R

The point shape can be changed in base R using the pch parameter:

plot(df[, "x"], df[, "y"], pch = seq(0, 25), cex = 3, lwd = 3,
     col = "#348FA7FF", bg = "#348FA755", 
     ylim = c(1, 5.3), axes = F, xlab = "", ylab = "")
text(df[, "x"], df[, "y"] + 0.3, labels = seq(0, 25), cex = 2)
26 different point shapes in base R

Available point shapes in ggplot2

The same symbols can be made in ggplot2 using the shape parameter:

library(ggplot2)

ggplot(df, aes_string(x = "x", y = "y"))+
  geom_point(shape = seq(0, 25), size = 5, stroke = 2,
             col = "#348FA7FF", fill = "#348FA755")+
  theme(axis.title = element_blank(),
        axis.ticks = element_blank(),
        axis.text = element_blank())+
  ylim(1, 5.3)+
  annotate(geom = "text", x = df[, "x"], y = df[, "y"],
           hjust = 0.5, vjust = -1.3, label = seq(0, 25), size = 6)
26 different point shapes in ggplot2
o

Conclusion

In conclusion, the same symbols can be plotted in both base R and ggplot2 but the parameters that control the shape, the size and the color of the symbols differ.

Related posts

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply