Search code examples
rggplot2plotvisualization

Get other shapes in R for geom_point


I need to replicate this exact visualisation but i can't find those shapes in R. How can I find, for example, the first shape from here which is square inside the square?

ggplot(df, aes(x=x_column,y=y_column, shape=shape, color=shape))+geom_point(size=4)+scale_shape_manual(values=c(0:25))enter image description here I implemented this code but the default values of shapes in R aren't the same as in sample plot


Solution

  • Those are standard shapes, but points are layered with different sizes.
    Building on reference examples of Aesthetic specifications and geom_point() :

    library(ggplot2)
    
    shapes <- data.frame(
      shape = c(0:25),
      x = 0:25 %/% 5,
      y = -(0:25 %% 5)
    )
    
    ggplot(shapes, aes(x,y,shape = factor(shape))) +
      geom_point(size = 4) +
      geom_point(size = 8) +
      scale_shape_manual(values = 0:25, 
                         guide = guide_legend(ncol = 3, keyheight = 1.8)) +
      theme_void() +
      coord_equal()
    

    Created on 2023-09-24 with reprex v2.0.2