On 4/16/2012 7:31 AM, Brian Smith wrote:> Hi,
>
> I was trying to replicate one of the graphs given on the ggplot2 website. I
> have given a sample code below. I would like to combine the legends, since
> each color is uniquely mapped to a shape.
>
> ###
> library(ggplot2)
>
> leaves<- letters[1:8]
> mat<- matrix(sample(1:1000,32),nrow=16,ncol=2)
> colnames(mat)<- paste('t',1:2,sep='')
> df<- as.data.frame(cbind(mat,leaves))
>
> vals<- 1:length(leaves)
> names(vals)<- leaves
>
> p<- ggplot(df,aes(t1,t2))
> p + aes(shape = factor(leaves)) + geom_point(aes(colour >
factor(leaves))) + scale_shape_manual("",values=vals)
>
> ####
>
> Which parameter do I need to change?
add scale_colour_discrete("") to your call. In order for scales to be
combined, the breaks, labels, and title must all be the same. You had
breaks and labels the same, but not the title. Alternatively, change
the scale_shape_manual call to scale_shape_manual(values=vals).
> thanks!
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University