[R] ggplot2: scale_shape_manual

Brian Diggs diggsb at ohsu.edu
Fri Apr 20 21:07:00 CEST 2012


On 4/19/2012 5:20 AM, Brian Smith wrote:
> Thanks Brian. That worked. I also wanted to increase the size of the
> 'points' on the graph. Is there any way I can get rid of the 'legend' (in
> this case '3') appearing on the plot?
>
> ======= code ====
>      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),size=3)) + scale_shape_manual(values=vals)

Move the size=3 outside the aes. That way it is set rather than mapped 
(when mapped, a legend is needed to show the reverse mapping)

p + aes(shape = factor(leaves)) + geom_point(aes(colour =
factor(leaves)),size=3) + scale_shape_manual(values=vals)

> =========
>
> thanks!
>
>
> On Mon, Apr 16, 2012 at 3:09 PM, Brian Diggs<diggsb at ohsu.edu>  wrote:
>
>> 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
>>
>> ______________________________**________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html<http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> 	[[alternative HTML version deleted]]
>


-- 
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University



More information about the R-help mailing list