Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Changing shapes used for scale_shape() in ggplot2

Writer Emily Wong

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?

3 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:

4

To complement Harlan's answer, here is a references for the available shapes - start from 0 at bottom left and read right then up (10y + x):

df <- data.frame(x=c(0:129))
ggplot(df, aes(x=x%%10, y=floor(x/10), shape=factor(x), colour=x, size=10)) + geom_point() + scale_shape_manual(values=df$x) + theme(legend.position='none') + scale_x_continuous(breaks=0:10) + scale_y_continuous(breaks=0:12) + scale_colour_hue() + scale_colour_gradientn(colours=rainbow(3))

Shapes available in ggplot2

> y <- rnorm(10)
> b <- as.factor(sample(1:4,10,replace=T))
> qplot(1:10, y, shape=b)
> qplot(1:10, y, pch=letters[1:10], cex=6)

Is this what you mean? I imagine you can use any of R's plotting characters...

This may not be a very 'ggplot' way of doing this though, but the man page does read "You can use it like you'd use the 'plot' function.". :-)

alt text

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy