Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing shapes used for scale_shape() in ggplot2

Tags:

r

ggplot2

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?

like image 678
Christopher DuBois Avatar asked Sep 25 '09 17:09

Christopher DuBois


People also ask

How do I change the shape of a point in 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.

What does shape do in Ggplot?

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.

What does geom_point () do in R?

The function geom_point() adds a layer of points to your plot, which creates a scatterplot.

How do I change the color of a geom point?

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.


1 Answers

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)) 

result of above

The shapes are the same as the usual 0-25 indexes: http://yusung.blogspot.com/2008/11/plot-symbols-in-r.html

like image 54
Harlan Avatar answered Oct 09 '22 00:10

Harlan