[R] Changing legend to fill colour in ggplot

Suparna Mitra suparna.mitra.sm at gmail.com
Thu Jun 27 09:34:37 CEST 2013


Hello R experts,
  I am having a problem to edit legend in ggplot using four variables.

My data structure is :
str(df)
'data.frame': 10 obs. of  6 variables:
 $ id                        : Factor w/ 2 levels "639A","640": 1 1 1 1 1 2
2 2 2 2
 $ species                   : Factor w/ 5 levels "acinetobacter_sp",..: 2
5 1 4 3 2 5 1 4 3
 $ genome_coverage_bp        : int  8196 3405 8625 22568 2128 6100 1841
3914 8487 1064
 $ genome_length             : int  3571237 2541445 3912725 3479613 5460977
3571237 2541445 3912725 3479613 5460977
 $ genome_coverage_percentage: Factor w/ 10 levels "0.02%","0.04%",..: 8 5
7 10 2 6 3 4 9 1
 $ avg_depth_coverage        : num  121.96 2.81 19.84 399.63 1.64 ...


Now what I did is
p=ggplot(df,aes(genome_coverage_percentage,avg_depth_coverage))+geom_point(aes(colour
= species,shape = factor(id)))
p+scale_shape_discrete(name  ="",labels=c("Patient 1", "Patient 2"))
That creats the plot below.
But I want to change the circles of legend in fill colour. So that it
doesn't look like it is only from Patient 1, as that also has circle.
Can anybody help me please?

Thanks a lot in advance :)
Mitra
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplot-5species.pdf
Type: application/pdf
Size: 181335 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130627/5db5ef7c/attachment.pdf>


More information about the R-help mailing list