{"id":234,"date":"2017-12-17T23:55:33","date_gmt":"2017-12-17T15:55:33","guid":{"rendered":"http:\/\/www.wuchangsong.com\/?p=234"},"modified":"2017-12-17T23:57:58","modified_gmt":"2017-12-17T15:57:58","slug":"ggplot2%ef%bc%9a%e6%b0%94%e6%b3%a1%e5%9b%be%e5%8f%8a%e6%95%a3%e7%82%b9%e5%9b%be%e5%b0%8f%e7%bb%93","status":"publish","type":"post","link":"http:\/\/www.wuchangsong.com\/?p=234","title":{"rendered":"ggplot2\uff1a\u6c14\u6ce1\u56fe\u53ca\u6563\u70b9\u56fe\u5c0f\u7ed3"},"content":{"rendered":"<p>\u6c14\u6ce1\u56fe\u4e5f\u5c5e\u4e8e\u6563\u70b9\u56fe\u7684\u4e00\u79cd\uff0c\u5728\u6563\u70b9\u56fe\u7684\u57fa\u7840\u4e0a\u6539\u53d8\u70b9\u7684\u5f62\u72b6\uff0c\u5927\u5c0f\u548c\u989c\u8272<\/p>\n<h4>1.\u5982\u4f55\u6539\u53d8\u70b9\u7684\u5f62\u72b6<\/h4>\n<p>\u7528\u81ea\u5e26\u7684mtcars\u6f14\u793a<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-237\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217230453.png\" alt=\"\" width=\"558\" height=\"122\" \/><\/p>\n<pre>p = ggplot(mtcars,aes(wt,mpg))\r\np + geom_point(shape=17,size=4)\r\np + geom_point(aes(shape = factor(cyl)),size=4)<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-238\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217231212.png\" alt=\"\" width=\"934\" height=\"438\" \/><\/p>\n<h4>2.\u6539\u53d8\u70b9\u7684\u5927\u5c0f\uff1a\u6c14\u6ce1\u56fe<\/h4>\n<p>\u52a0\u8f7d\u5305\u3001\u6570\u636e\u7684\u8bfb\u5165\u53ca\u6570\u636e\u683c\u5f0f<\/p>\n<pre>library(ggplot2)\r\npathway = read.table(\"R0-vs-R3.path.richFactor.head20.tsv\",header=T,sep=\"\\t\")<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-243\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217232824.png\" alt=\"\" width=\"748\" height=\"230\" \/><\/p>\n<h4>3.\u521d\u59cb\u5316\u6570\u636e<\/h4>\n<pre>pp = ggplot(pathway,aes(richFactor,Pathway))\r\npp + geom_point()<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-244\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217233114.png\" alt=\"\" width=\"451\" height=\"450\" \/><\/p>\n<h4>\u6c14\u6ce1\u56fe\uff08\u4e09\u7ef4\u6570\u636e\uff09,size \u53ef\u4ee5\u662f\u4e00\u4e2a\u503c\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u636e\u4e2d\u7684\u4e00\u5217<\/h4>\n<pre>pp + geom_point(aes(size=R0vsR3))<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-245\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217233550.png\" alt=\"\" width=\"606\" height=\"543\" \/><\/p>\n<h4>\u6dfb\u52a0\u989c\u8272\u53d8\u5316\u2014\u2014\u56db\u7ef4\u6570\u636e<\/h4>\n<p>scale_colour_gradient\uff1a\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fde\u7eed\u578b\u7684\u914d\u8272\uff0c\u5e38\u7528\u4e8e\u70ed\u56fe\uff1b<\/p>\n<pre>pbubble = pp + geom_point(aes(size=R0vsR3,color=-1*log10(Qvalue)))\r\npbubble\r\npbubble + scale_colour_gradient(low=\"green\",high=\"red\")<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-247\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217234422.png\" alt=\"\" width=\"1197\" height=\"463\" \/><br \/>\nexpression\u51fd\u6570\u6539\u53d8\u6837\u5f0f\uff0c[]\u662f\u7528\u6765\u6dfb\u52a0\u4e0b\u6807\uff0c^\u662f\u7528\u6765\u6dfb\u52a0\u4e0a\u6807<\/p>\n<pre>pr = pbubble + scale_colour_gradient(low=\"green\",high=\"red\") + labs(color=expression(-log[10](Qvalue)),size=\"Gene number\",x=\"Rich factor\",y=\"Pathway name\",title=\"Top20 of pathway enrichment\")\r\npr\r\npr + theme_bw()<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-248\" src=\"http:\/\/www.wuchangsong.com\/wp-content\/uploads\/2017\/12\/QQ\u56fe\u724720171217234830.png\" alt=\"\" width=\"1209\" height=\"447\" \/><\/p>\n<h4>\u6563\u70b9\u56fe\u5c0f\u7ed3<\/h4>\n<p>\u2022 \u989c\u8272: color\/colour \uff08\u53ef\u6e10\u53d8\uff09<br \/>\n\u2022 \u5f62\u72b6\uff1ashape<br \/>\n\u2022 \u5927\u5c0f\uff1asize \uff08\u53ef\u6e10\u53d8\uff09<br \/>\n\u2022 \u900f\u660e\u5ea6\uff1aalpha \uff08\u7ec3\u4e60\uff09<br \/>\n\u2022 \u6539\u53d8\u5750\u6807\u8f74\u7684\u8303\u56f4: xlim()\u548cylim()\u51fd\u6570<br \/>\n\u2022 \u6539\u53d8\u6807\u9898\uff0c\u5750\u6807\u8f74\u6807\u9898\u548clegend\u6807\u9898:labs()\u51fd\u6570<br \/>\n\u2022 \u4fdd\u5b58\u56fe\u7247\uff1aggsave()\u51fd\u6570<br \/>\n\u652f\u6301\u591a\u79cd\u56fe\u7247\u683c\u5f0f\uff1apng,pdf,svg\u7b49<\/p>\n<pre>ggsave(\"pathway_enrichment.png\")\r\nggsave(\"pathway_enrichment_gray.png\",pr)\r\nggsave(\"volcano4.pdf\",volcano,width=4,height=4)\r\nggsave(\"volcano8.pdf\",volcano,width=8,height=8)<\/pre>\n<h4>\u7ed8\u5236\u76f4\u7ebf\u5c0f\u7ed3<\/h4>\n<p>\u2022 geom_abline(slope=xx,intercept=xx): \u7ed8<br \/>\n\u5236\u76f4\u7ebf<br \/>\n\u2022 geom_hline(yintercept=xx):\u7ed8\u5236\u6c34\u5e73\u7ebf<br \/>\n\u2022 geom_vline(xintercept=xx):\u7ed8\u5236\u5782\u76f4\u7ebf<br \/>\n\u2022 size: \u7ebf\u6761\u7c97\u7ec6<br \/>\n\u2022 color: \u7ebf\u6761\u989c\u8272<br \/>\n\u2022 linetype: \u7ebf\u6761\u7c7b\u578b<\/p>\n<p>\u8be6\u7ec6\u8bb2\u89e3\u53c2\u8003<a href=\"http:\/\/docs.ggplot2.org\/current\/\">ggplot2\u8bf4\u660e\u6587\u6863<\/a>\u548c<a href=\"http:\/\/www.omicshare.com\">\u57fa\u8fea\u5965<\/a>\u5728\u7ebf\u89c6\u9891<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6c14\u6ce1\u56fe\u4e5f\u5c5e\u4e8e\u6563\u70b9\u56fe\u7684\u4e00\u79cd\uff0c\u5728\u6563\u70b9\u56fe\u7684\u57fa\u7840\u4e0a\u6539\u53d8\u70b9\u7684\u5f62\u72b6\uff0c\u5927\u5c0f\u548c\u989c\u8272 1.\u5982\u4f55\u6539\u53d8\u70b9\u7684\u5f62\u72b6 \u7528\u81ea\u5e26\u7684mtcars\u6f14\u793a p = ggplot(mtcars,aes(wt,mpg)) p + geom_point(shape=17,size=4) p + geom_point(aes(shape = factor(cyl)),size=4) 2.\u6539\u53d8\u70b9\u7684\u5927\u5c0f\uff1a\u6c14\u6ce1\u56fe \u52a0\u8f7d\u5305\u3001\u6570\u636e\u7684\u8bfb\u5165\u53ca\u6570\u636e\u683c\u5f0f library(ggplot2) pathway = read.table(&#8220;R0-vs-R3.path.richFactor.head20.tsv&#8221;,header=T,sep=&#8221;\\t&#8221;) 3.\u521d\u59cb\u5316\u6570\u636e pp = ggplot(pathway,aes(richFactor,Pathway)) pp + geom_point() \u6c14\u6ce1\u56fe\uff08\u4e09\u7ef4\u6570\u636e\uff09,size \u53ef\u4ee5\u662f\u4e00\u4e2a\u503c\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u636e\u4e2d\u7684\u4e00\u5217 pp + geom_point(aes(size=R0vsR3)) \u6dfb\u52a0\u989c\u8272\u53d8\u5316\u2014\u2014\u56db\u7ef4\u6570\u636e scale_colour_gradient\uff1a\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fde\u7eed\u578b\u7684\u914d\u8272\uff0c\u5e38\u7528\u4e8e\u70ed\u56fe\uff1b pbubble = pp + geom_point(aes(size=R0vsR3,color=-1*log10(Qvalue))) pbubble pbubble + scale_colour_gradient(low=&#8221;green&#8221;,high=&#8221;red&#8221;) expression\u51fd\u6570\u6539\u53d8\u6837\u5f0f\uff0c[]\u662f\u7528\u6765\u6dfb\u52a0\u4e0b\u6807\uff0c^\u662f\u7528\u6765\u6dfb\u52a0\u4e0a\u6807 pr = pbubble + scale_colour_gradient(low=&#8221;green&#8221;,high=&#8221;red&#8221;) + labs(color=expression(-log[10](Qvalue)),size=&#8221;Gene number&#8221;,x=&#8221;Rich factor&#8221;,y=&#8221;Pathway name&#8221;,title=&#8221;Top20 of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/234"}],"collection":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=234"}],"version-history":[{"count":3,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":251,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions\/251"}],"wp:attachment":[{"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wuchangsong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}