ggplot2 - R scatterplot, legend not shown -


i'm having following data set in r want plot in scatterplot.

     user  distance time 1    1  8.559737    4 2    1  5.013872    5 3    1 11.168995    9 4    1  4.059428    4 5    1  3.928071    4  6    1 12.403195    7 

i generate plot using following r code.

plot <- ggplot(scatter, aes(x=scatter[['distance']], y=scatter[['time']])) +            geom_point(shape=16, size=5, colour=scatter[['user']]) +            scale_x_continuous("distance", limits=c(0,100), breaks=seq(0, 100, 10)) +            scale_y_continuous("time", limits=c(0,20), breaks=seq(0, 20, 2))  png(filename="scatters/0_2_scatter.png", width=800, height=800) plot(plot) dev.off() 

this results in following plot. enter image description here

why legend not shown? isn't defining colour in geom_point sufficient? i'm trying generate legend containing black dot , text 'user1'.

try:

ggplot(scatter, aes(x=distance, y=time)) +            geom_point(shape=16, size=5, mapping = aes(colour=user)) +            scale_x_continuous("distance", limits=c(0,100), breaks=seq(0, 100, 10)) +            scale_y_continuous("time", limits=c(0,20), breaks=seq(0, 20, 2)) 

the whole purpose of having data argument separate specifications in aes() ggplot non-standard evaluation allowing refer (unquoted) column names. don't ever refer columns via $ or [[ or [ inside of aes().

the legend should appear when map aesthetics (i.e. use aes()), hadn't color.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -