{"id":23375,"date":"2024-01-04T17:35:13","date_gmt":"2024-01-04T09:35:13","guid":{"rendered":"http:\/\/www.biocloudservice.com\/wordpress\/?p=23375"},"modified":"2024-01-04T17:35:14","modified_gmt":"2024-01-04T09:35:14","slug":"ggpubr%e5%8c%85%e5%bf%ab%e9%80%9f%e5%be%97%e5%88%b0%e7%9b%b8%e5%85%b3%e6%80%a7%e5%88%86%e6%9e%90%e5%9b%be","status":"publish","type":"post","link":"http:\/\/www.biocloudservice.com\/wordpress\/?p=23375","title":{"rendered":"ggpubr\u5305\u5feb\u901f\u5f97\u5230\u76f8\u5173\u6027\u5206\u6790\u56fe"},"content":{"rendered":"<p><strong>\u4ec0\u4e48\u662f\u76f8\u5173\u6027\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u76f8\u5173\u6027\u5206\u6790\u7528\u4e8e\u8bc4\u4f30\u4e24\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u8054\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u77e5\u9053\u7236\u6bcd\u4eb2\u7684\u8eab\u9ad8\u548c\u5b69\u5b50\u7684\u8eab\u9ad8\u4e4b\u95f4\u662f\u5426\u5b58\u5728\u5173\u7cfb\uff0c\u53ef\u4ee5\u8ba1\u7b97\u7236\u6bcd\u4eb2\u4e0e\u5b69\u5b50\u7684\u76f8\u5173\u7cfb\u6570\u6765\u56de\u7b54\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u8ba1\u7b97\u76f8\u5173\u6027\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662fPearson\u76f8\u5173\u65b9\u6cd5\u3002\u76ae\u5c14\u900a\uff08Pearson\uff09\u76f8\u5173\uff08r\uff09\uff0c\u5b83\u6d4b\u91cf\u4e24\u4e2a\u53d8\u91cf\uff08x\u548cy\uff09\u4e4b\u95f4\u7684\u7ebf\u6027\u76f8\u5173\u6027\u3002\u5b83\u4e5f\u79f0\u4e3a\u53c2\u6570\u76f8\u5173\u6027\u68c0\u9a8c\uff0c\u56e0\u4e3a\u5b83\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u5206\u5e03\u3002\u4ec5\u5f53x\u548cy\u6765\u81ea\u6b63\u6001\u5206\u5e03\u65f6\u624d\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002y = f\uff08x\uff09\u7684\u56fe\u79f0\u4e3a\u7ebf\u6027\u56de\u5f52\u66f2\u7ebf\u3002<\/p>\n<p>\u76f8\u5173\u6027\u5206\u6790\u4e00\u76f4\u662f\u7814\u7a76\u8005\u70ed\u8877\u4e8e\u7528\u7684\u4e00\u79cd\u5206\u6790\uff0c\u6307\u51fa\u4e24\u4e2a\u6216\u591a\u4e2a\u5177\u5907\u76f8\u5173\u6027\u7684\u53d8\u91cf\u5143\u7d20\u8fdb\u884c\u5206\u6790\uff0c\u4ece\u800c\u8861\u91cf\u4e24\u4e2a\u56e0\u7d20\u7684\u76f8\u5173\u5bc6\u5207\u7a0b\u5ea6\uff0c\u76f8\u5173\u6027\u7684\u5143\u7d20\u4e4b\u95f4\u9700\u8981\u5b58\u5728\u4e00\u5b9a\u7684\u8054\u7cfb\u6216\u8005\u6982\u7387\u624d\u53ef\u4ee5\u8fdb\u884c\u76f8\u5173\u6027\u5206\u6790\u3002ggpubr\u662f\u57fa\u4e8eggplot2\u7684\u4e00\u4e2a\u5305\uff0c\u5728\u753b\u56fe\u7684\u65f6\u5019\u6bd4\u8f83\u7701\u4e8b\uff0c\u7528\u4e00\u884c\u4ee3\u7801\u53ef\u4ee5\u505a\u76f8\u5173\u6027\u5206\u6790\u3002<\/p>\n<h2>\u5b89\u88c5\u52a0\u8f7d\u5b89\u88c5\u5305<\/h2>\n<p>\u7b2c\u4e00\u79cd\u76f4\u63a5\u5b89\u88c5R\u5305<\/p>\n<p>install.packages(&#8220;ggpubr&#8221;)<\/p>\n<p>library(ggpubr)<\/p>\n<p>\u7b2c\u4e8c\u4e2d\u901a\u8fc7github\u5b89\u88c5<\/p>\n<p>if(!require(devtools)) install.packages(&#8220;devtools&#8221;)<\/p>\n<p>devtools::install_github(&#8220;kassambara\/ggpubr&#8221;)<\/p>\n<p>library(ggpubr)<\/p>\n<h2>\u57fa\u7840\u7ed8\u5236\u76f8\u5173\u6027\u5206\u6790\u56fe<\/h2>\n<p>#mtcars<\/p>\n<p>ggscatter(mtcars, x = &#8220;wt&#8221;, y = &#8220;mpg&#8221;,<\/p>\n<p>color = &#8220;black&#8221;, size = 3, # \u70b9\u7684\u989c\u8272\u4e0e\u5927\u5c0f<\/p>\n<p>add = &#8220;reg.line&#8221;, # \u6dfb\u52a0\u56de\u5f52\u7ebf<\/p>\n<p>add.params = list(color = &#8220;red&#8221;, fill = &#8220;lightgray&#8221;), # \u56de\u5f52\u7ebf\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\u7ea2\u8272\uff0c\u533a\u95f4\u989c\u8272\u8bbe\u7f6e\u4e3a\u7070\u8272<\/p>\n<p>conf.int = TRUE, # \u6dfb\u52a0\u56de\u5f52\u7ebf\u7684\u7f6e\u4fe1\u533a\u95f4<\/p>\n<p>cor.coef = TRUE, # \u6dfb\u52a0\u76f8\u5173\u7cfb\u6570<\/p>\n<p>cor.coeff.args = list(method = &#8220;pearson&#8221;, label.x = 3, label.sep = &#8220;\\n&#8221;)#\u9009\u62e9Pearson\u76f8\u5173<\/p>\n<p>)<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"500\" class=\"wp-image-23378\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-57-10.png?resize=640%2C500\" alt=\"\u622a\u5c4f2023-06-09 11.57.10\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-57-10.png?w=676 676w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-57-10.png?resize=300%2C234 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-57-10.png?resize=600%2C469 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<h2>\u4fbf\u6377\u7684\u6dfb\u52a0R\u548cP\u7684\u4f5c\u7528<\/h2>\n<p>#\u7528R\u4e2d\u7684\u81ea\u5e26\u9e22\u5c3e\u82b1\u7684\u6570\u636e\u8fdb\u884c\u5206\u6790\u53ef\u4ee5<\/p>\n<p>data(&#8220;iris&#8221;)<\/p>\n<p>p &lt;- ggplot(data = iris, aes(x = Sepal.Width, y = Petal.Width, color = Species)) + geom_point() + geom_smooth(method = lm) +<\/p>\n<p>scale_color_manual(values = c(&#8216;#FF7400&#8217;, &#8216;#009999&#8217;, &#8216;#3914AF&#8217;)) +<\/p>\n<p>labs(title = &#8216;iris&#8217;) +<\/p>\n<p>theme_bw() + theme(plot.title = element_text(hjust = 0.5)) +<\/p>\n<p>stat_cor(method = &#8216;pearson&#8217;, aes(x = Sepal.Width, y = Petal.Width, color = Species))<\/p>\n<p>p<\/p>\n<p>#stat_cor\u53ef\u4ee5\u4e4b\u95f4\u6dfb\u52a0R\u548cP\u503c\uff0c\u505a\u4e0d\u540c\u7684\u9e22\u5c3e\u82b1\u7684\u79cd\u7c7b\u7684\u82b1\u843c\u7247Sepal\u5bbd\u5ea6\u4e0e\u82b1\u74e3Petal\u5bbd\u5ea6\u7684\u76f8\u5173\u6027\uff0c\u4e0eggplot\u7528\u6cd5\u7c7b\u4f3c\uff0c\u7528\u65af\u76ae\u5c14\u66fc\u7684\u7b97\u6cd5\u6765\u8fdb\u884c\u8ba1\u7b97pearson\uff0c\u6dfb\u52a0\u70b9geom_point\u548c\u5e73\u6ed1\u7684\u66f2\u7ebfgeom_smooth\uff0c\u8bbe\u7f6e\u4e0d\u540c\u7684\u989c\u8272\uff0c\u8bbe\u7f6e\u4e3b\u9898\u7b49theme_bw()\u7b49\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"640\" height=\"495\" class=\"wp-image-23379\" src=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?resize=640%2C495\" alt=\"\u622a\u5c4f2023-06-09 11.55.53\" srcset=\"https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?w=1036 1036w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?resize=300%2C232 300w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?resize=1024%2C793 1024w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?resize=768%2C595 768w, https:\/\/i0.wp.com\/www.biocloudservice.com\/wordpress\/wp-content\/uploads\/2024\/01\/2023-06-09-11-55-53.png?resize=600%2C464 600w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-recalc-dims=\"1\" \/><\/p>\n<p>\u5176\u5b9eggpubr\u5305\u4e0d\u4ec5\u53ef\u4ee5\u5feb\u901f\u7684\u505a\u51fa\u76f8\u5173\u6027\u5206\u6790\u7684\u56fe\uff0c\u8fd8\u53ef\u4ee5\u7ed8\u5236\u5bc6\u5ea6\u56fe\u3001\u76f4\u65b9\u56fe\u3001\u7bb1\u7ebf\u56fe\u3001\u6563\u70b9\u56fe\u3001\u5c0f\u63d0\u7434\u56fe\u7b49\uff0c\u5e76\u4e14\u5728\u6dfb\u52a0p\u503c\u7b49\u64cd\u4f5c\u4e0a\u66f4\u52a0\u7684\u7b80\u4fbf\u3002ggpubr\u5305\u6db5\u76d6\u4e86\u5341\u6765\u79cd\u51fd\u6570\uff0c\u8fd130\u79cd\u56fe\u5f62\uff0c\u53ef\u4ee5\u6ee1\u8db3\u65e5\u5e38\u79d1\u7814\u6240\u9700\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>ggdensity() \u5bc6\u5ea6\u56fe<\/li>\n<li>stat_overlay_normal_density() \u5bc6\u5ea6\u56fe\uff0c\u540c\u65f6\u53e0\u52a0\u6b63\u6001\u5206\u5e03\u7684\u56fe\uff0c\u6709\u52a9\u4e8e\u68c0\u67e5\u504f\u79bb\u503c<\/li>\n<li>gghistogram() \u76f4\u65b9\u56fe\u3002<\/li>\n<li>ggecdf() \u7ecf\u9a8c\u7d2f\u79ef\u5bc6\u5ea6\u5206\u5e03\u56fe<\/li>\n<li>ggqqplot() \u5206\u4f4d\u6570-\u5206\u4f4d\u6570\u56fe\uff0c\u7b80\u79f0QQ\u56fe\u3002<\/li>\n<li>ggboxplot() \u7bb1\u56fe<\/li>\n<li>ggviolin() \u5c0f\u63d0\u7434\u56fe<\/li>\n<li>ggdotplot() \u70b9\u56fe<\/li>\n<li>ggstripchart() strip chart, \u4e5f\u53ef\u4ee5\u79f0\u4e3a\u4e00\u7ef4\u6563\u70b9\u56fe\u3002<\/li>\n<li>ggbarplot() \u67f1\u72b6\u56fe<\/li>\n<li>ggline() \u7ebf\u56fe<\/li>\n<li>ggerrorplot() Visualizing Error \u7ed8\u5236\u8bef\u5dee\u68d2\u56fe<\/li>\n<li>ggpie() \u997c\u56fe<\/li>\n<li>ggdonutchart() \u751c\u751c\u5708\u997c\u56fe<\/li>\n<li>ggdotchart()theme_cleveland() \u514b\u5229\u592b\u5170\u70b9\u56fe<\/li>\n<li>ggscatter() \u6563\u70b9\u56fe\uff0cstat_cor() \u5c06\u6709P\u503c\u7684\u76f8\u5173\u7cfb\u6570\u6dfb\u52a0\u5230\u6563\u70b9\u56fe\u4e2d\uff0cstat_stars())<\/li>\n<\/ul>\n<p>\u597d\u4e86\uff0c\u8fd9\u6837\u6211\u4eec\u7684\u76f8\u5173\u6027\u5206\u6790\u5c31\u505a\u597d\u4e86\uff0c\u5c0f\u4f19\u4f34\u4eec\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\u5c31\u548c\u5c0f\u679c\u8ba8\u8bba\u5427\uff5e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u76f8\u5173\u6027\u5206\u6790\uff1a \u76f8\u5173\u6027\u5206\u6790\u7528\u4e8e\u8bc4\u4f30\u4e24\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u4e4b\u95f4\u7684\u5173\u8054\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u77e5\u9053\u7236\u6bcd\u4eb2\u7684\u8eab\u9ad8\u548c\u5b69\u5b50\u7684\u8eab\u9ad8\u4e4b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23375"}],"collection":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23375"}],"version-history":[{"count":1,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23375\/revisions"}],"predecessor-version":[{"id":23380,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/23375\/revisions\/23380"}],"wp:attachment":[{"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23375"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.biocloudservice.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}