r - geom_point with different legend for fill and shape -
hmmm, maybe it's temprature or i'm once again not see obvious ...
here code:
library(ggplot2) p <- ggplot() p <- p + geom_point(aes(x = 1, y=1,bg = "i", group = "b"),pch = 21, size = 20, color=na) p <- p + geom_point(aes(x = 1, y=1.125,bg = "i", group = "b" ),pch = 22, size = 20, color=na) p <- p + geom_point(aes(x = 0.75, y=1.125,bg = "ii", group = "a" ),pch = 22, size = 20, color=na) p <- p + geom_point(aes(x = 0.85, y=1.125,bg = "iii", group = "a" ),pch = 22, size = 20, color=na) p <- p + scale_fill_manual(values= c("darkred", "darkblue", "darkgreen"), guide=guide_legend(override.aes = list(shape = 23))) #p <- p + scale_fill_manual(values= c("darkred", "darkblue", "darkgreen"), guide=guide_legend(inherit.aes = false)) p <- p + scale_shape_manual(labels = c("circle", "rectangle"),values = c(21, 22)) p what i'm trying achieve 2 legends, 1 reflects color, in example there 3 different colors ("i", "ii", , "iii"), , 2 different types of shapes "rectangle" , "circle", there never more these 2 different shapes.
unfortunately there additional constraints ... can't use aesthetic color due fact i'm using geom_segment somehow connect shapes, , second constraint, have use ggplot2.
but i'not able produce these 2 legends, appreciated ...
why don't store points in data frame? suits perfectly:
df <- data.frame(x = c(1, 1, 0.75, 0.85), y = c(1, 1.125, 1.125, 1.125), nr = c("i", "i", "ii", "iii"), sh = c("b", "b", "a", "a")) and can see required mapping:
ggplot(df, aes(x, y, fill = nr, shape = sh)) + geom_point(size = 20, color = na) + scale_shape_manual(labels = c("circle", "rectangle"), values = c(21, 22), guide = guide_legend(override.aes = list(colour = 1))) + scale_fill_manual(values = c("darkred", "darkblue", "darkgreen"), guide = guide_legend(override.aes = list(shape = 23))) 
Comments
Post a Comment