[R] Mirror Image on Biplot Graphic

Rodrigo Aluizio r.aluizio at gmail.com
Tue Oct 7 21:47:04 CEST 2008


Sorry for the mistake, I'm trying to rotate the CAP 1 axis not 2!
Ah well, I tried the this other way, but it gave me an error.
Something in the syntax, I tried to change something but didn't fix the 
error.

CAPpotiFTI<-CAPpotiFT
 for(i in c(2:8,15)) CAPpotiFTI$CCA[[i]][,2]<-CAPpotiFTI,cca$CCA[[i]][,1]*-1
Erro: unexpected ',' in "for(i in c(2:8,15)) 
CAPpotiFTI$CCA[[i]][,2]<-CAPpotiFTI,"

 for(i in c(2:8,15)) CAPpotiFTI$CCA[[i]][,1]<-CAPpotiFTI$CCA[[i]][,1]*-1
Erro em CAPpotiFTI$CCA[[i]] : índice fora de limites (index out of limits)

Well, it needs lots of patience...

--------------------------------------------------
From: "Mark Difford" <mark_difford em yahoo.co.uk>
Sent: Tuesday, October 07, 2008 3:50 PM
To: <r-help em r-project.org>
Subject: Re: [R] Mirror Image on Biplot Graphic

>
> Hi Rodrigo,
>
> Again an error, as that doesn't touch one of the data structures. You need
> to extend the range to include #15, as below:
>
> ## This does axis 2
> mynew.cca <- my.cca
> for (i in c(2:8,15)) mynew.cca$CCA[[i]][, 2] <- mynew,cca$CCA[[i]][, 2] 
> * -1
>
> Cheers, Mark.
>
>
> Mark Difford wrote:
>>
>> Hi Rodrigo,
>>
>> I looked through my scripts and found my old hack. __WARNING__: Be very
>> careful to check that
>> the mirror isn't broken and that all is in order! Make sure that you are
>> reversing the axes you want. In your original post you mention axis 2,
>> i.e. y-axis. Below you have used axis 1.
>>
>> ## This does axis 2
>> mynew.cca <- my.cca
>> for (i in 2:8) mynew.cca$CCA[[i]][, 2] <- mynew,cca$CCA[[i]][, 2] * -1
>>
>> plot(mynew.cca)
>>
>> ## This does axis 1
>> for (i in 2:8) mynew.cca$CCA[[i]][, 1] <- mynew,cca$CCA[[i]][, 1] * -1
>>
>> Regards, Mark.
>>
>>
>> Rodrigo Aluizio wrote:
>>>
>>> Ok Mark, it worked for the species.
>>> I still get an error if I try with biplot (cn,sp), but it's not a
>>> problem,
>>> repositioning the species is enough.
>>> Thanks once again.
>>>
>>> Just for future consults the error that still remains:
>>> CAPpotiFTI<-scores(CAPpotiFT, display=c('bp','species','cn','sites')
>>> CAPpotiFTI$species[,1]<-CAPpotiFTI$species[,1]*-1
>>> CAPpotiFTI$cn[,1]<-CAPpotiFTI$cn[,1]*-1
>>> CAPpotiFTI$sites[,1]<-CAPpotiFTI$sites[,1]*-1
>>> CAPpotiFTI$bp[,1]<-CAPpotiFTI$bp[,1]*-1
>>>  plot.cca(CAPpotiFTI,type='none',display=c('bp','species'),main='Total
>>> Fauna
>>> + Species x Environment')
>>> Erro em match.arg(display) : 'arg' must be of length 1
>>>
>>> or
>>>
>>> text.cca(scores(CAPpotiFTI$biplot),col=323232,cex=0.6,lwd=2,lty='dotted')
>>> Doesn't return an error, but it's not a mirror image as expected, it's
>>> nonsense.
>>>
>>> --------------------------------------------------

>>> Sent: Tuesday, October 07, 2008 12:22 PM
>>> To: <r-help em r-project.org>
>>> Subject: Re: [R] Mirror Image on Biplot Graphic
>>>
>>>>
>>>> Hi Rodrigo,
>>>>
>>>> Sorry again: the structure vegan uses is quite complex. Technically you
>>>> should use the extractor function scores() to extract what you want 
>>>> from
>>>> the
>>>> object, e.g. scores(my.cca, display="species") or scores(my.cca,
>>>> display="cn") [centroids]. I did work out a quicker way of reversing
>>>> axes,
>>>> but that seems to have gone walking...and I am not using vegan at the
>>>> moment.
>>>>
>>>> Quickest hack is to make a copy of the objects you want to plot,
>>>> reversing
>>>> orientations along the way. So do (my.cca is your original object):
>>>>
>>>> Temp.data <- scores(my.cca, display=c("sites", "species", "cn"))
>>>>
>>>> ## Reverse yaxes
>>>> Temp.data$sites[, 2] <- Temp.data$sites[, 2] * -1
>>>> Temp.data$species[, 2] <- Temp.data$species[, 2] * -1
>>>> Temp.data$centroid[, 2] <- Temp.data$centroid[, 2] * -1
>>>>
>>>> Do this for all the things you are plotting whose axes you want
>>>> reversed.
>>>> Check this against your original plot to ensure that the mirror isn't
>>>> broken.
>>>>
>>>> You can then use the Temp.data with the scores() function to make your
>>>> plot.
>>>>
>>>> ## Mock e.g.
>>>> points(scores(Temp.data, display="sites"), pch=21)
>>>>
>>>> Regards, Mark.
>>>>
>>>>
>>>> Rodrigo Aluizio wrote:
>>>>>
>>>>>> Thanks a lot for your help (again) Mark.
>>>>>> I adapted your suggestion to my analysis.
>>>>>> But I'm getting and error when trying to apply the new values.
>>>>>> The error is:
>>>>>>
>>>>>> Erro em scores(CAPpotiFTI)$species[, 2] <-
>>>>>> scores(CAPpotiFTI)$species[,
>>>>>> :
>>>>>>  não foi posssível encontrar a função "scores<-"
>>>>>>
>>>>>> Translating:
>>>>>> Error at scores(CAPpotiFTI)$species[, 2] <-
>>>>>> scores(CAPpotiFTI)$species[,
>>>>>> :
>>>>>>  it's not possible to find the function "scores<-"
>>>>>>
>>>>>> Bellow how I applied the suggestion:
>>>>>> CAPpotiFTI<-CAPpotiFT
>>>>>> scores(CAPpotiFTI)$species[,2]<-scores(CAPpotiFTI)$species[,2]*-1
>>>>>> scores(CAPpotiFTI)$sites[,2]<-scores(CAPpotiFTI)$sites[,2]*-1
>>>>>>
>>>>>> Any ideas? I'm trying similar things but without success.
>>>>>>
>>>>>> --------------------------------------------------
>>>
>>>>>> Sent: Tuesday, October 07, 2008 10:34 AM
>>>>>> To: <r-help em r-project.org>
>>>>>> Subject: Re: [R] Mirror Image on Biplot Graphic
>>>>>>
>>>>>>>
>>>>>>> Hi Rodrigo,
>>>>>>>
>>>>>>> Sorry, that will not return a result (I use several different
>>>>>>> ordination
>>>>>>> packages, in most of which this is possible). What you need to do
>>>>>>> with
>>>>>>> vegan
>>>>>>> is the following:
>>>>>>>
>>>>>>> scores(mynew.cca)$species[, 2] <- scores(mynew.cca)$species[, 2] 
>>>>>>> * -1
>>>>>>>
>>>>>>> You will be able to do the rest.
>>>>>>>
>>>>>>> Regards, Mark.
>>>>>>>
>>>>>>>
>>>>>>> Mark Difford wrote:
>>>>>>>>
>>>>>>>> Hi Rodrigo,
>>>>>>>>
>>>>>>>>>> I need to rotate on y axis the lines and symbols of constrained
>>>>>>>>>> and
>>>>>>>>>> sites representation.
>>>>>>>>
>>>>>>>> Easiest is to multiply the axis you want to invert by -1. Something
>>>>>>>> like
>>>>>>>> the following, where my.cca is the orginal object and yax = obj[, 
>>>>>>>> 2]
>>>>>>>> (xax
>>>>>>>> being obj[, 1]). Obviously, copying isn't necessary.
>>>>>>>>
>>>>>>>> mynew.cca <- my.cca
>>>>>>>> mynew.cca$scores$species[, 2] <- my.cca$scores$species[, 2] * -1
>>>>>>>> mynew.cca$scores$sites[, 2] <- my.cca$scores$sites[, 2] * -1
>>>>>>>> mynew.cca$scores$centroids[, 2] <- my.cca$scores$centroids[, 2] 
>>>>>>>> * -1
>>>>>>>>
>>>>>>>> Regards, Mark.
>>>>>>>>
>>>>>>>>
>>>>>>>> Rodrigo Aluizio wrote:
>>>>>>>>>
>>>>>>>>> He everybody,
>>>>>>>>> Well I have a biplot CCA-like origined from plot.cca (vegan
>>>>>>>>> package).
>>>>>>>>> I
>>>>>>>>> need to rotate on y axis the lines and symbols of constrained and
>>>>>>>>> sites
>>>>>>>>> representation. If I do that on an image editor, I rotate
>>>>>>>>> everything,
>>>>>>>>> including titles, axes labels and positions. I just need to rotate
>>>>>>>>> the
>>>>>>>>> inner par and keep the variables names (constrained) and symbols 
>>>>>>>>> in
>>>>>>>>> the
>>>>>>>>> new positions but with the right direction.
>>>>>>>>> So, is there on R a way to do that while creating the image?
>>>>>>>>> Here is the code that generate the graphic.
>>>>>>>>>
>>>>>>>>> plot.cca(CAPpotiFT,type='none',display=c('bp','sites'),main='Total
>>>>>>>>> Fauna
>>>>>>>>> Sites x Environment')
>>>>>>>>> text.cca(CAPpotiFT,dis='cn',col='black',cex=0.6,lwd=0.5,lty='dotted')
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='1',],pch=21)
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='2',],pch=20)
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='3',],pch=22,bg='gray')
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='4',],pch=24)
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='5',],pch=24,bg='black')
>>>>>>>>> points(ScoresCAPFT$sites[FatoresRep$BiofaciesBC=='6',],pch=25,bg='gray')
>>>>>>>>>
>>>>>>>>> Thanks in advice.
>>>>>>>>> ___________________________________
>>>>>>>>> MSc. Rodrigo Aluizio
>>>>>>>>> Centro de Estudos do Mar/UFPR
>>>>>>>>> Laboratório de Micropaleontologia
>>>>>>>>>
>>>>>>>>> [[alternative HTML version deleted]]
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ______________________________________________
>>>>>>>>> R-help em 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.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> View this message in context:
>>>>>>> http://www.nabble.com/Mirror-Image-on-Biplot-Graphic-tp19857549p19858268.html
>>>>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>>>>
>>>>>>> ______________________________________________
>>>>>>> R-help em 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.
>>>>>>>
>>>>>
>>>>> ______________________________________________
>>>>> R-help em 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.
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> View this message in context:
>>>> http://www.nabble.com/Mirror-Image-on-Biplot-Graphic-tp19857549p19860594.html
>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>
>>>> ______________________________________________
>>>> R-help em 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.
>>>>
>>>
>>> ______________________________________________
>>> R-help em 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.
>>>
>>>
>>
>>
>
> -- 
> View this message in context: 
> http://www.nabble.com/Mirror-Image-on-Biplot-Graphic-tp19857549p19864798.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help em 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.
>



More information about the R-help mailing list