wrongusername
wrongusername

Reputation: 18918

ggplot2 grouping legend

I have a data frame trajectory_df that has the following structure:

table

The uid row has 6 different possible values, each representing a particular user. So I want to plot 6 lines on the same plot, and I'm currently doing it in this way:

ggplot(trajectory_df, aes(Month, Pagerank, colour=uid, group=uid)) + geom_line() + geom_point() + scale_x_discrete(breaks=month_ticks)

Which gives me this picture:

the graph

Which is just what I want, except for the legend. I want there to be 6 different entries in the legend, not a colorful range of values.

How can I accomplish this?

Upvotes: 3

Views: 203

Answers (1)

joran
joran

Reputation: 173517

Try this instead:

ggplot(trajectory_df, aes(Month, Pagerank, colour=factor(uid), group=uid)) + 
   geom_line() + 
   geom_point() + 
   scale_x_discrete(breaks=month_ticks)

Upvotes: 6

Related Questions