r - ggplot: Scatter plot, labels and legend -


consider following example (taken post on stackoverflow):

require(ggplot2) d <- data.frame(x = c(102856,17906,89697,74384,91081,52457,73749,29910,75604,28267,122136, 54210,48925,58937,76281,67789,69138,18026,90806,44893), y = c(2818, 234, 2728, 2393, 2893, 1015, 1403, 791, 2243, 596, 2468, 1495, 1232, 1746, 2410, 1791, 1706, 259, 1982, 836), names = c("a","c","e","d","g","f","i","h","k","m","l","n","q","p","s","r","t","w","v","y")) ggplot(d, aes(x,y,col=names)) + geom_point() + geom_text(aes(label=names),hjust=1,vjust=1) 

running , without last "geom_text" layer changes legend (the bullet becomes bullet symbol superposed on it).

could explain me why, , how can avoid change ? thanks.

as set color= inside ggplot() call, colors used points , text labels , legend made points (default symbol point) , texts (default symbol a). if add in aes() of ggplot() affects layers uses such parameter, if new argument isn't added layer. if need change color text labels don't want show in legend add argument show_guide=false inside geom_text().

ggplot(d, aes(x,y,color=names)) + geom_point() +    geom_text(aes(label=names),hjust=1,vjust=1,show_guide=false) 

if want change color points color= argument should placed in aes() of geom_point(), affect colors of points.

ggplot(d, aes(x,y)) + geom_point(aes(color=names)) +    geom_text(aes(label=names),hjust=1,vjust=1) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -