Josep Maria Campanera Alsina
2008-Dec-19 17:32 UTC
[R] How to plot arrows for a PLS plot with ggplot2?
Dear community, I'd like to build a PLS plot with scores and loadings, sometimes called "biplot". Like in biplot.mvr {pls} but using ggplot2. 1. Scores plot. No problem! ggplot(data=data1,aes(x=plsr1,y=plsr2))+geom_point(aes(colour=solenergy,shape=type))+geom_text(aes(label=res,size=1,hjust=0,vjust=0)) where,> str(data1)'data.frame': 295 obs. of 5 variables: $ plsr1 : num 1.60 1.49 1.42 1.17 1.35 ... $ plsr2 : num -1.822 -1.987 -0.758 0.172 0.421 ... $ res : Factor w/ 18 levels "ARG","ASN","ASP",..: 1 1 1 1 1 1 1 1 1 1 ... $ type : Factor w/ 2 levels "Alfa_Helix","Beta_Sheet": 2 2 2 2 2 2 2 2 2 2 2. Loadings plot. Here it is where my struggle comes from with ggplot2. The Loadings are in this dataset!> str(data2)'data.frame': 4 obs. of 9 variables: $ plsr1 : num 0.9522 0.2986 -0.0898 0.1561 $ plsr2 : num 0.2287 -0.9686 -0.1017 0.0105 $ xnew : num 0 0 0 0 $ ynew : num 0 0 0 0 Aparently with plain R is fairly simple, although I cannot override to the previous plot.>plot(data2$plsr1,data2$plsr2) >arrows(data2$xnew,data2$ynew,data2$plsr1,data2$plsr2,lwd=2,length = 0.2, angle = 30)How to do that with ggplot2 and override it to the previous scores plot? with geom_segment apparently you can do that, but how? Anyone can give me a clue? Thanks in advance and congratulations for ggplot2! It is great! Josep Maria, --------------------------------------------- Josep Maria Campanera Alsina Professor Lector Departament de Fisicoqu?mica Facultat de Farm?cia Universitat de Barcelona Avgda Joan XXIII, s/n 08028 Barcelona ? Catalonia ? Spain Tel: +34 93 4035985 Fax: +34 93 4035987 campanera at ub.edu