Suppose I have the following
y <- rnorm(10) b <- as.factor(sample(1:4,10,replace=T)) qplot(1:10, y, shape=b)
How do I change the shapes that are used using ggplot2
?
Change point shapes, colors and sizes manually :scale_shape_manual() : to change point shapes. scale_color_manual() : to change point colors. scale_size_manual() : to change the size of points.
In ggplot, point shapes can be specified in the function geom_point() . Key arguments include: shape : numeric values as pch for setting plotting points shapes. size : numeric values cex for changing points size.
The function geom_point() adds a layer of points to your plot, which creates a scatterplot.
To color the points in a scatterplot using ggplot2, we can use colour argument inside geom_point with aes. The color can be passed in multiple ways, one such way is to name the particular color and the other way is to giving a range or using a variable.
The ggplot way to do it would be to use scale_shape_manual
and provide the desired shapes in the values
argument:
qplot(1:10, y, shape=b) + scale_shape_manual(values = c(0, 5, 6, 15))
The shapes are the same as the usual 0-25 indexes: http://yusung.blogspot.com/2008/11/plot-symbols-in-r.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With