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)](https://i0.wp.com/www.biolinfo.com/wp-content/uploads/point_shapes_in_base_R_and_ggplot2.png?resize=683%2C1024&ssl=1)
Comparison of parameters
To begin, the point types can be customized using the following parameters:
Parameters | In base R | In ggplot2 |
point character / symbol | pch | shape |
character expansion / extension | cex | size |
line width (not for symbols between 15 and 18 in base R) | lwd | stroke |
color | col | col / color / colour |
background (not for symbols between 0 and 20) | bg | fill |
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](https://i0.wp.com/www.biolinfo.com/wp-content/uploads/plot_symbols_in_base_R.png?resize=1000%2C600&ssl=1)
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](https://i0.wp.com/www.biolinfo.com/wp-content/uploads/plot_symbols_in_ggplot2.png?resize=1024%2C614&ssl=1)
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.