Boxplot from dataframe...
3
0
Entering edit mode
David Ruau ▴ 110
@david-ruau-1473
Last seen 10.2 years ago
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I wrote a little function to do a boxplot for a row element of a numeric matrix. Indeed for a specific probeset of a expression value matrix but the problem is not with bioconductor functions but on the right use of R. Is there a simpler way to do a boxplot for a specific probeset from either a AffyBatch or an expression matrix? - ---- code ---- myboxplot <- function(id,e.mat){ require(mgu74av2) # grab the expression values x <- e.mat[rownames(e.mat)==id] # make column of those expression value c1 <- as.list(t(x[1:3])) # Exp1 c2 <- as.list(t(x[4:6])) # Exp2 c3 <- as.list(t(x[7:9])) # Exp3 c4 <- as.list(t(x[10:12])) # Exp4 c5 <- as.list(t(x[13:14])) # Exp5 c6 <- as.list(t(x[15:17])) # Exp6 # Little transformation for c5 as there is only 2 value for it and 3 for the others. c5 <- c(c5, NA) # because only 2 values # combinaison of the column x <- cbind(c1,c2,c3,c4,c5,c6) # Convert to a dataframe x <- as.data.frame(x) # Add name to the column colnames(x) <- c("Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6") # Grab gene name for plot's title y <- mget (id, env= mgu74av2GENENAME) names(y) <- NULL boxplot(x) title(main=y, sub=id) } - ---- Thanks, David -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFDwmHB7EoGVUIQyhERAuRiAJ491zrSB/zD7P8aRMkc7nKPu496rwCggnsi gi2RwP7t2CQcC0pTsTVFsos= =6H0E -----END PGP SIGNATURE-----
convert convert • 1.4k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States
David Ruau wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > I wrote a little function to do a boxplot for a row element of a > numeric matrix. Indeed for a specific probeset of a expression value > matrix but the problem is not with bioconductor functions but on the > right use of R. > > Is there a simpler way to do a boxplot for a specific probeset from > either a AffyBatch or an expression matrix? > - ---- code ---- > myboxplot <- function(id,e.mat){ > > require(mgu74av2) > # grab the expression values > x <- e.mat[rownames(e.mat)==id] > > # make column of those expression value > c1 <- as.list(t(x[1:3])) # Exp1 > c2 <- as.list(t(x[4:6])) # Exp2 > c3 <- as.list(t(x[7:9])) # Exp3 > c4 <- as.list(t(x[10:12])) # Exp4 > c5 <- as.list(t(x[13:14])) # Exp5 > c6 <- as.list(t(x[15:17])) # Exp6 > > # Little transformation for c5 as there is only 2 value for it and 3 > for the others. > c5 <- c(c5, NA) # because only 2 values > > # combinaison of the column > x <- cbind(c1,c2,c3,c4,c5,c6) > > # Convert to a dataframe > x <- as.data.frame(x) > > # Add name to the column > colnames(x) <- c("Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6") > > # Grab gene name for plot's title > y <- mget (id, env= mgu74av2GENENAME) > names(y) <- NULL > > boxplot(x) > title(main=y, sub=id) > } That is a lot of work to get a boxplot. You should be able to get the same thing with much less work. y <- get(id, mgu74av2GENENAME) expt <- as.factor(rep(1:6, each=3)[-13]) boxplot(exprs(e.mat)[id,]~expt, main = y, sub = id, names = paste("Exp", 1:6, sep="")) > - ---- > Thanks, > David > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (Darwin) > > iD8DBQFDwmHB7EoGVUIQyhERAuRiAJ491zrSB/zD7P8aRMkc7nKPu496rwCggnsi > gi2RwP7t2CQcC0pTsTVFsos= > =6H0E > -----END PGP SIGNATURE----- > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor -- James W. MacDonald Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623
ADD COMMENT
0
Entering edit mode
Thanks for the hint. I rewrote the program Here is how it looks like when apply to AffyBatch which contain a phenoData vector "population" describing the data structure. The thing I can't managed to do without going through a matrix to stock the expression data, is to have the name of the corresponding experiment below each boxplot (i.e for the moment I have the default numbering). the first version of the script (see bottom) is doing that not this new one. This one is creating a legend inside the graph. ## # usage: myboxplot("1234_at", abatch) myboxplot <- function(id,abatch){ require(mgu74av2) require(gplots) require(RColorBrewer) # Grab title y <- mget (id, env= mgu74av2GENENAME) names(y) <- NULL # Colors colors <- brewer.pal(9, "Set1") boxplot(exprs(abatch)[rownames(exprs(abatch))==id] ~ abatch$population, col=colors) title(main=y, sub=id) smartlegend(x="left",y="top", inset=0, c("1: Exp1", "2: Exp2", "3: Exp3", "4: Exp4", "5: Exp5", "6: Exp6"), fill=colors) } #end On Jan 9, 2006, at 15:49, James W. MacDonald wrote: > David Ruau wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> Hi, >> I wrote a little function to do a boxplot for a row element of a >> numeric matrix. Indeed for a specific probeset of a expression value >> matrix but the problem is not with bioconductor functions but on the >> right use of R. >> Is there a simpler way to do a boxplot for a specific probeset from >> either a AffyBatch or an expression matrix? >> - ---- code ---- >> myboxplot <- function(id,e.mat){ >> require(mgu74av2) >> # grab the expression values >> x <- e.mat[rownames(e.mat)==id] >> # make column of those expression value >> c1 <- as.list(t(x[1:3])) # Exp1 >> c2 <- as.list(t(x[4:6])) # Exp2 >> c3 <- as.list(t(x[7:9])) # Exp3 >> c4 <- as.list(t(x[10:12])) # Exp4 >> c5 <- as.list(t(x[13:14])) # Exp5 >> c6 <- as.list(t(x[15:17])) # Exp6 >> # Little transformation for c5 as there is only 2 value for it and 3 >> for the others. >> c5 <- c(c5, NA) # because only 2 values >> >> # combinaison of the column >> x <- cbind(c1,c2,c3,c4,c5,c6) >> >> # Convert to a dataframe >> x <- as.data.frame(x) >> # Add name to the column >> colnames(x) <- c("Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6") >> >> # Grab gene name for plot's title >> y <- mget (id, env= mgu74av2GENENAME) >> names(y) <- NULL >> boxplot(x) >> title(main=y, sub=id) >> } > > That is a lot of work to get a boxplot. You should be able to get the > same thing with much less work. > > y <- get(id, mgu74av2GENENAME) > expt <- as.factor(rep(1:6, each=3)[-13]) > boxplot(exprs(e.mat)[id,]~expt, main = y, sub = id, names = > paste("Exp", 1:6, sep="")) >> - ---- >> Thanks, >> David >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.1 (Darwin) >> iD8DBQFDwmHB7EoGVUIQyhERAuRiAJ491zrSB/zD7P8aRMkc7nKPu496rwCggnsi >> gi2RwP7t2CQcC0pTsTVFsos= >> =6H0E >> -----END PGP SIGNATURE----- >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor > > > -- > James W. MacDonald > Affymetrix and cDNA Microarray Core > University of Michigan Cancer Center > 1500 E. Medical Center Drive > 7410 CCGC > Ann Arbor MI 48109 > 734-647-5623
ADD REPLY
0
Entering edit mode
I found out finally how to have the names of the experiments printed on the x axis by using the phenoData define in the affyBatch. ### boxplot(exprs(abatch)[rownames(exprs(abatch))==id] ~ abatch$population, col=colors, axes=FALSE) title(main=y, sub=id) axis(1, at = 1:length(unique(da.gcrma$population)), labels = as.list(unique(da.gcrma$exp))) axis(2) box() ### David
ADD REPLY
0
Entering edit mode
@wolfgang-huber-3550
Last seen 3 months ago
EMBL European Molecular Biology Laborat…
Hi David, I am not sure I understand what you want to achieve but if x is a matrix, something like sx = x[ logicalvector, ] boxplot(sx ~ col(sx), col="mistyrose") should do the job. And if x is a dataframe you can even do away with the "~col(sx)". You might also want to have a look at the multiecdf and multidensity functions in the devel version of geneplotter. Cheers Wolfgang David Ruau wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > I wrote a little function to do a boxplot for a row element of a > numeric matrix. Indeed for a specific probeset of a expression value > matrix but the problem is not with bioconductor functions but on the > right use of R. > > Is there a simpler way to do a boxplot for a specific probeset from > either a AffyBatch or an expression matrix? > - ---- code ---- > myboxplot <- function(id,e.mat){ > > require(mgu74av2) > # grab the expression values > x <- e.mat[rownames(e.mat)==id] > > # make column of those expression value > c1 <- as.list(t(x[1:3])) # Exp1 > c2 <- as.list(t(x[4:6])) # Exp2 > c3 <- as.list(t(x[7:9])) # Exp3 > c4 <- as.list(t(x[10:12])) # Exp4 > c5 <- as.list(t(x[13:14])) # Exp5 > c6 <- as.list(t(x[15:17])) # Exp6 > > # Little transformation for c5 as there is only 2 value for it and 3 > for the others. > c5 <- c(c5, NA) # because only 2 values > > # combinaison of the column > x <- cbind(c1,c2,c3,c4,c5,c6) > > # Convert to a dataframe > x <- as.data.frame(x) > > # Add name to the column > colnames(x) <- c("Exp1", "Exp2", "Exp3", "Exp4", "Exp5", "Exp6") > > # Grab gene name for plot's title > y <- mget (id, env= mgu74av2GENENAME) > names(y) <- NULL > > boxplot(x) > title(main=y, sub=id) > } > - ---- > Thanks, > David > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (Darwin) > > iD8DBQFDwmHB7EoGVUIQyhERAuRiAJ491zrSB/zD7P8aRMkc7nKPu496rwCggnsi > gi2RwP7t2CQcC0pTsTVFsos= > =6H0E > -----END PGP SIGNATURE----- > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor -- Best regards Wolfgang ------------------------------------- Wolfgang Huber European Bioinformatics Institute European Molecular Biology Laboratory Cambridge CB10 1SD England Phone: +44 1223 494642 Fax: +44 1223 494486 Http: www.ebi.ac.uk/huber
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States
David Ruau wrote: > > I found out finally how to have the names of the experiments printed on > the x axis by using the phenoData define in the affyBatch. > ### > boxplot(exprs(abatch)[rownames(exprs(abatch))==id] ~ abatch$population, > col=colors, axes=FALSE) > title(main=y, sub=id) > axis(1, at = 1:length(unique(da.gcrma$population)), labels = > as.list(unique(da.gcrma$exp))) > axis(2) > box() > ### > > David Why don't you just use the 'names' argument to boxplot() for the x-axis labeling? In addition, you don't need the logical vector rownames(exprs(abatch))==id to subset a matrix. You can simply use the rowname, which is at the very least less typing, and may well be faster. exprs(abatch)[id,] Jim -- James W. MacDonald Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623
ADD COMMENT

Login before adding your answer.

Traffic: 488 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