> ggplot2 should make legends automatically if the data is in the
> correct format. If you could send a reproducible example, that would
> help detect the error.


Take the following two plots. The first one produces a broken line. In the 
second one, the variable Phase is numeric and therefore it does not break the 
line between two "Phases". That is why I am trying to do it by assigning a 
number to the "Phase" and then use different labels in the legend. If I put the 
text of those labels in the variable Phase itself, as done in the first 
example, it gives me a broken line.

# Plot 1

data.frame(Year=c(1:20),CDR=rnorm(20))->b3
c(rep("a",10),rep("b",10))->b3$Phase
qplot(Year,CDR,data=b3,colour=Phase,geom=c("point","line"),gpar(legend.position="bottom"))->p
p

#Plot 2

data.frame(Year=c(1:20),CDR=rnorm(20))->b3
c(rep(1,10),rep(2,10))->b3$Phase
qplot(Year,CDR,data=b3,colour=Phase,geom=c("point","line"),gpar(legend.position="bottom"))->p
p+scale_colour_gradient2(limits=c(1,2), 
midpoint=1.5,low="magenta",high="darkblue",breaks=c(1,2),labels=c("a","b"))->p
p

Also, legend.position does not work. I am sure I am not doing it the right way.

I appreciate your help.

Vikas



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to