Geting going..

9 views
Skip to first unread message

smelov

unread,
Dec 9, 2010, 7:01:43 PM12/9/10
to ggplot2
I do a lot of gene expression work, and recently came across ggplot2
(purchased the book etc). I think this could be a lot more facile for
exploring my data, other than slogging through R, combined with excel,
but I'm not sure.

Most of my data is in the following form:
Individual 1 Individual 2 Individual 3
Individual 4.....and so on, can be upto a 100 individuals or so
Gene1 8.6 9.2
10.2 12.2
Gene 2 7.6 9.3
10.8 11.3
Gene 3 .........................................................
...
..

you get the idea, can be upto 50,000 genes.

I'd like to explore the data in a fashion similar to the direction I
see from some other posters, i.e. group several individuals (for
example "Diseased"), and plot the mean of suites of genes (or
individually) I identify via other criteria versus a control group. I
saw a post from Hadley indicating that perhaps ggplot2 wasnt the best
for doing these sorts of large data displays.

Is anyone doing routine plotting using ggplot2 for exploring the data
of large scale gene expression data sets? I get the sense there is
more than a few people reading this forum doing just that (of course
I'm aware there are thousands of people using other solutions for this
as well). In contrast to the other solutions, ggplot2 seems inherently
more elegant than combining R and excel.

thanks in advance.



Brandon Hurr

unread,
Dec 10, 2010, 4:56:29 AM12/10/10
to smelov, ggplot2
I wouldn't say I'm doing routine analysis, but it's something I'm certainly interested in doing. When I first started using R it was my impression that R is not the best tool for working with such large datasets, but I happen to think that it will work with them and that you'll probably need some patience to do so. 

I have played with a dataset similar to yours previously but at the time I knew very little about R and ggplot2. First off I found that you needed to rotate your data.frame using t(). Once you did that you needed to make it a data.frame again and add all your labels back. Maybe there's a better way and it's probably easier to do in excel. 


tomato<-read.delim("", header=-T)

tomato<-t(tomato)

#the dataset I have attached is already transformed and has descriptive factors in the columns to the left

Once you have that then you should have your subjects/individuals in the rows and your genes in columns. At this point it would be good to make sure that if you have any descriptive factors that they are also in columns (I usually put them to the left, but I guess it doesn't really matter). 

If you want to condense your data for an average or other statistical description) it would probably be a good idea to use melt() from the reshape package at this point to get everything in long format so you can use ddply and then graph. I've found that if you use ddply and then melt that the column names get a bit messy. 

molten.tomato<-melt(tomato, id.vars=c("cultivar", "time", "Calcium", "MCP", "rep"))

> head(molten.tomato)
   cultivar time Calcium MCP rep variable    value
1 CultivarA    1       0   0   1     RNA1 45.04535
2 CultivarA    1       0   0   2     RNA1 65.66946
3 CultivarA    1       0   0   3     RNA1 47.29543
4 CultivarA    1       1   0   1     RNA1 52.11987
5 CultivarA    1       1   0   2     RNA1 50.78511
6 CultivarA    1       1   0   3     RNA1 57.18179

Say I wanted the average, SEM and count of my reps... 
#std.error requires the plotrix package
tomato.rep.avg<-ddply(molten.tomato, c("cultivar", "time","Calcium", "MCP", "variable"), 
function(df) return(c(mean=mean(df[["value"]],na.rm=TRUE)
, se=std.error(df[["value"]], na.rm=TRUE)
, count=nrow(df))), .progress="text")

> head(tomato.rep.avg)
   cultivar time Calcium MCP variable     mean       se count
1 CultivarA    1       0   0     RNA1 52.67008 6.532066     3
2 CultivarA    1       0   0     RNA2 59.37547 5.814488     3
3 CultivarA    1       0   0     RNA3 59.29170 1.769940     3
4 CultivarA    1       0   0     RNA4 58.38911 8.026655     3
5 CultivarA    1       0   0     RNA5 53.64641 5.093122     3
6 CultivarA    1       0   0     RNA6 54.29813 2.121581     3

From there there are a million ways to graph it. You could subset the data by the RNA name or the treatment and plot it by timepoint. You could cast the data back out to wide format and use the averages to do a PCA/PLS plot. What sort of plots do you find most useful when looking at this sort of data? 

I'm very eager to work on this problem and am more than willing to contribute to an effort to create a routine analysis function that outputs analysis data and graphs in ggplot.

Brandon 



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

tomato.example.transcript.data.r
Reply all
Reply to author
Forward
0 new messages