suggestions for plotPCA / pca.legend
1
0
Entering edit mode
Jenny Drnevich ★ 2.2k
@jenny-drnevich-382
Last seen 9.7 years ago
Hi Jim, I've been playing around with the versatility of plotPCA - thanks for adding support for matrices! Say I have a 2x2 factorial design, and I want to plot the 4 groups, but not using 4 separate symbols, each with its own color. Instead, I want use 2 symbols to indicate the levels of the first factor and 2 colors to indicate the levels of the second factor. I can do this by using the arguments "pch" and "col" instead of "groups". However, the legend doesn't come out correctly - instead of the 4 symbol/color groups, there are only 2 - one symbol in one color and the other symbol in the other color. I looked at pca.legend and I think I've come up with a fix. At the very beginning, instead of: pch <- sort(unique(pch)) col <- sort(unique(col)) this worked to give the correct legend: gps <- sort(unique(paste(pch,col,sep="A"))) pch <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[1])) col <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[2])) It might also be good to include some sort of warning if length(groupnames)!=length(gps); if you forget to put in groupnames in the original call to plotPCA, it defaults to the names of the columns, and the legend symbols get recycled so that the legend is incorrect. Cheers, Jenny Jenny Drnevich, Ph.D. Functional Genomics Bioinformatics Specialist W.M. Keck Center for Comparative and Functional Genomics Roy J. Carver Biotechnology Center University of Illinois, Urbana-Champaign 330 ERML 1201 W. Gregory Dr. Urbana, IL 61801 USA ph: 217-244-7355 fax: 217-265-5066 e-mail: drnevich at uiuc.edu
• 1.7k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 hours ago
United States
Hi Jenny, Thanks for the input. I'll have to think about it, but right now I am not too keen on making this change. I worry that adding something clever for a specific purpose might backfire with an unintended consequence. Note however that the devel version of affycoretools has a 'legend' argument that you can set to FALSE to supress the legend. You can then add the correct legend by hand. Best, Jim Jenny Drnevich wrote: > Hi Jim, > > I've been playing around with the versatility of plotPCA - thanks for > adding support for matrices! Say I have a 2x2 factorial design, and I want > to plot the 4 groups, but not using 4 separate symbols, each with its own > color. Instead, I want use 2 symbols to indicate the levels of the first > factor and 2 colors to indicate the levels of the second factor. I can do > this by using the arguments "pch" and "col" instead of "groups". However, > the legend doesn't come out correctly - instead of the 4 symbol/color > groups, there are only 2 - one symbol in one color and the other symbol in > the other color. I looked at pca.legend and I think I've come up with a > fix. At the very beginning, instead of: > > pch <- sort(unique(pch)) > col <- sort(unique(col)) > > this worked to give the correct legend: > > gps <- sort(unique(paste(pch,col,sep="A"))) > pch <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[1])) > col <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[2])) > > > It might also be good to include some sort of warning if > length(groupnames)!=length(gps); if you forget to put in groupnames in the > original call to plotPCA, it defaults to the names of the columns, and the > legend symbols get recycled so that the legend is incorrect. > > Cheers, > Jenny > > > > > > Jenny Drnevich, Ph.D. > > Functional Genomics Bioinformatics Specialist > W.M. Keck Center for Comparative and Functional Genomics > Roy J. Carver Biotechnology Center > University of Illinois, Urbana-Champaign > > 330 ERML > 1201 W. Gregory Dr. > Urbana, IL 61801 > USA > > ph: 217-244-7355 > fax: 217-265-5066 > e-mail: drnevich at uiuc.edu > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
ADD COMMENT
0
Entering edit mode
At 12:20 PM 1/17/2007, James W. MacDonald wrote: >Hi Jenny, > Hi Jim, I understand your concerns! I did check to make sure the change resulted in the same legend if used the traditional way, but I understand that "works now" means " *should* work in the future, but there are no guarantees" :) Even without the legend change, the suggested warning could be useful to detect mistakes, such as 'groupnames' not being given when needed, or if 'pch' and 'col' were used directly, but incorrectly. As always, thanks for the great affycoretools package! Jenny >Thanks for the input. I'll have to think about it, but right now I am not >too keen on making this change. I worry that adding something clever for a >specific purpose might backfire with an unintended consequence. > >Note however that the devel version of affycoretools has a 'legend' >argument that you can set to FALSE to supress the legend. You can then add >the correct legend by hand. > >Best, > >Jim > >Jenny Drnevich wrote: >>Hi Jim, >>I've been playing around with the versatility of plotPCA - thanks for >>adding support for matrices! Say I have a 2x2 factorial design, and I >>want to plot the 4 groups, but not using 4 separate symbols, each with >>its own color. Instead, I want use 2 symbols to indicate the levels of >>the first factor and 2 colors to indicate the levels of the second >>factor. I can do this by using the arguments "pch" and "col" instead of >>"groups". However, the legend doesn't come out correctly - instead of the >>4 symbol/color groups, there are only 2 - one symbol in one color and the >>other symbol in the other color. I looked at pca.legend and I think I've >>come up with a fix. At the very beginning, instead of: >>pch <- sort(unique(pch)) >>col <- sort(unique(col)) >>this worked to give the correct legend: >>gps <- sort(unique(paste(pch,col,sep="A"))) >>pch <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[1])) >>col <- as.numeric(sapply(strsplit(gps,"A"),function(x) x[2])) >> >>It might also be good to include some sort of warning if >>length(groupnames)!=length(gps); if you forget to put in groupnames in >>the original call to plotPCA, it defaults to the names of the columns, >>and the legend symbols get recycled so that the legend is incorrect. >>Cheers, >>Jenny >> >> >>Jenny Drnevich, Ph.D. >>Functional Genomics Bioinformatics Specialist >>W.M. Keck Center for Comparative and Functional Genomics >>Roy J. Carver Biotechnology Center >>University of Illinois, Urbana-Champaign >>330 ERML >>1201 W. Gregory Dr. >>Urbana, IL 61801 >>USA >>ph: 217-244-7355 >>fax: 217-265-5066 >>e-mail: drnevich at uiuc.edu >>_______________________________________________ >>Bioconductor mailing list >>Bioconductor at stat.math.ethz.ch >>https://stat.ethz.ch/mailman/listinfo/bioconductor >>Search the archives: >>http://news.gmane.org/gmane.science.biology.informatics.conductor > > >-- >James W. MacDonald, M.S. >Biostatistician >Affymetrix and cDNA Microarray Core >University of Michigan Cancer Center >1500 E. Medical Center Drive >7410 CCGC >Ann Arbor MI 48109 >734-647-5623 > > >********************************************************** >Electronic Mail is not secure, may not be read every day, and should not >be used for urgent or sensitive issues. Jenny Drnevich, Ph.D. Functional Genomics Bioinformatics Specialist W.M. Keck Center for Comparative and Functional Genomics Roy J. Carver Biotechnology Center University of Illinois, Urbana-Champaign 330 ERML 1201 W. Gregory Dr. Urbana, IL 61801 USA ph: 217-244-7355 fax: 217-265-5066 e-mail: drnevich at uiuc.edu
ADD REPLY

Login before adding your answer.

Traffic: 601 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6