r - ggplot2 guide/legend on shape -


i have plot following script.

require(ggplot2)  df.shape <- data.frame( ax = runif(10), ay = runif(10), bx = runif(10, 2, 3), = runif(10, 2, 3) )  p <- ggplot(df.shape) p <- p + geom_point(aes(x = ax, y = ay, shape = 15)) +      geom_point(aes(x = bx, y = by, shape = 19)) +      scale_shape_identity() +      guides(shape = guide_legend(override.aes = list(shape = 15, shape = 19)) ) print(p) 

this doesn't produce legend, describing shape "a" , shape "b". note squares , circles may close 1 another, can't define variable based on location. how display "shape" legend?

i reshape data in long format using reshape:

dt <- reshape(df.shape ,direction='long', varying=list(c(1, 3), c(2, 4)),         ,v.names = c('x','y'), times = c('a','b')) 

then plot

 ggplot(dt) +      geom_point(aes(x = x, y = y, shape = time),size=5) +      scale_shape_manual(values=c(15,19)) 

enter image description here


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -