开发者

sorting dotplot factor axis in ggplot

I have a data.frame with gene expression data and I want to create a graph in ggplot2. here's an example for my data frame:

Gene.Name    cell.type    expression
ABC          heart        12
AZF          heart        13  
ABC          kidney       1
AZF          kidney       2

and forth. in reality there are 160 genes, 5 tissue types.

I drew a dotplot with the following code:

a <- ggplot(data, aes(x = expression, y = Gene.Name))
a + geom_point() + facet_grid(. ~ cell.type)

Here's a snapshot of the plot

http://i55.tinypic.com/2rgonjp.jpg

what I want to do but can't seem to manage is to order the genes alphabeti开发者_开发知识库cally. I tried:

a <- ggplot(data, aes(x = expression, reorder(Gene.Name, Gene.Name)))

but this didn't work (the Gene.Name column is alphabetically sorted, so I thought this might change the order but it didn't)

Any suggestions as to how I might change the gene name order?

Thanks


Changed the name to "dat" because "data" is a bad dog. Use rev to reverse the order of the levels on the factor variable. Your code was missing a closing paren in the first line and misspelled geom_point() in the second:

dat$Gene.Name <- factor(dat$Gene.Name, levels= levels(rev(dat$Gene.Name))
a <- ggplot(dat, aes(x = expression, y = Gene.Name))
a + geom_point() + facet_grid(. ~ cell.type)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜