Plotting a shape reference palette for ggplot2
Shapes are picked following a default scale when you input a variable to work as shape
using ggplot2
. You can always choose to tweak this scale to one of your preference. To do so you need to know which shapes are available and how you can call for them. This recipe simply draws the following shape palette:
Figure 2.4 - ggplot2 shape palette.
It shows available points, plus the number used to call for them. Now let's explore the code that built it.
How to do it...
Draw a suitable data frame using rep()
and seq()
functions, them let's plot those using geom_point()
:
> palette <- data.frame(x = rep(seq(1,5,1),5))
> palette$y <- c(rep(5,5),rep(4,5),rep(3,5),rep(2,5),rep(1,5))
> library(ggplot2)
> ggplot(data = palette,aes(x,y)) +
geom_point(shape = seq(1,25,1), size = 10, fill ='white') +
scale_size(range = c(2, 10)) +
geom_text(nudge_y = .3, label = seq(1,25,1))
Function geom_text()
is plotting the reference numbers related...