-2

I have this code:

my dataset:

 founder wt.Df Replicate Block Food_Source Viability   avg_val
1       A3  5905         1     1    Nicotine 0.4444444 0.4444444
2       A3 24834         1     1    Nicotine 0.6190476 0.6190476
3       A3 27861         1     1    Nicotine 0.4210526 0.5200501
4       A3 27861         2     1    Nicotine 0.6190476 0.5200501
5       A4  5905         1     1    Nicotine 0.7142857 0.7689076
6       A4  5905         2     1    Nicotine 0.8235294 0.7689076
7       A4 24834         1     1    Nicotine 0.4285714 0.5476190
8       A4 24834         1     1    Nicotine 0.6666667 0.5476190
9       A4 27861         1     1    Nicotine 0.6666667 0.6904762
10      A4 27861         1     1    Nicotine 0.7142857 0.6904762

qplot(x=founder, y=avg_val, group=wt.Df, data=Store, geom="line", colour = Store$wt.Df,      main= "QCT on Nicotine", xlab = "Founder", ylab = "Average Viability") + geom_point()

enter image description here

What I want to do is define what each line is meaning using Store$wt.Df, I want to see what color line corresponds to it and label this to the right under legend wt.Df

Chad
  • 149
  • 4
  • 11
  • How many lines do you want? Right now, you set `group = wt.Df` which looks continuous, which means you'll only plot lines when there are multiple points that share `wt.Df` values. (But maybe you have `wt.Df` as a factor? If you use `dput` to post data we can be sure.) It sounds like what you describe is what you already have, but it's hard to believe that it's what you want. You should probably use `ggplot` not `qplot` if you're doing anything that's not a default. – Gregor Thomas Mar 03 '14 at 22:44

1 Answers1

1

I'm not quite sure what you want. Could it be as easy as changing colour=Store$wt.Df to colour=factor(Store$wt.Df)?

Store = read.table(text="founder wt.Df Replicate Block Food_Source Viability   avg_val
1       A3  5905         1     1    Nicotine 0.4444444 0.4444444
2       A3 24834         1     1    Nicotine 0.6190476 0.6190476
3       A3 27861         1     1    Nicotine 0.4210526 0.5200501
4       A3 27861         2     1    Nicotine 0.6190476 0.5200501
5       A4  5905         1     1    Nicotine 0.7142857 0.7689076
6       A4  5905         2     1    Nicotine 0.8235294 0.7689076
7       A4 24834         1     1    Nicotine 0.4285714 0.5476190
8       A4 24834         1     1    Nicotine 0.6666667 0.5476190
9       A4 27861         1     1    Nicotine 0.6666667 0.6904762
10      A4 27861         1     1    Nicotine 0.7142857 0.6904762",header=TRUE)

qplot(x=founder, y=avg_val, group=wt.Df, data=Store, geom="line", colour = factor(Store$wt.Df),      
      main= "QCT on Nicotine", xlab = "Founder", ylab = "Average Viability") + geom_point()

enter image description here

kdauria
  • 6,300
  • 4
  • 34
  • 53
  • by any chance can I actually modify the legend title? sorry to ask. I am very new with ggplot2 and qplot – Chad Mar 03 '14 at 22:48
  • http://stackoverflow.com/questions/14622421/how-to-change-legend-title-in-ggplot-density – kdauria Mar 03 '14 at 22:49
  • http://stackoverflow.com/questions/6910988/change-both-legend-titles-in-a-ggplot-with-two-legends?rq=1 – kdauria Mar 03 '14 at 22:51