{"id":449,"date":"2023-04-26T16:05:43","date_gmt":"2023-04-26T16:05:43","guid":{"rendered":"https:\/\/yunshangtulv.com.cn\/?p=449"},"modified":"2023-04-26T16:05:43","modified_gmt":"2023-04-26T16:05:43","slug":"%e9%ab%98%e5%88%86sci%e5%9b%be%e7%89%87%e5%a4%8d%e7%8e%b0%ef%bc%9a%e7%ae%b1%e7%ba%bf%e5%9b%be%e6%95%a3%e7%82%b9%e5%9b%be","status":"publish","type":"post","link":"https:\/\/yunshangtulv.com.cn\/?p=449","title":{"rendered":"\u9ad8\u5206SCI\u56fe\u7247\u590d\u73b0\uff1a\u7bb1\u7ebf\u56fe+\u6563\u70b9\u56fe"},"content":{"rendered":"<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 bg-gray-50 dark:bg-[#444654]\">\n<div class=\"text-base gap-4 md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap break-words\">\n<div class=\"markdown prose w-full break-words dark:prose-invert dark\">\n<p>\u4f7f\u7528\u793a\u4f8b\u6570\u636e\u8fdb\u884c\uff0c\u8bf7\u6839\u636e\u5b9e\u9645\u9700\u8981\u8c03\u6574<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre class=\"corepress-code-pre\"><code># \u521b\u5efa\u865a\u62df\u6570\u636e\uff1a\r\nBacteroides_A &lt;- runif(50, min = -17, max = -12)\r\nBacteroides_B &lt;- runif(50, min = -15.5, max = -10)\r\nBMI_A &lt;- runif(50, min = 3.45, max = 4.2)\r\nBMI_B &lt;- runif(50, min = 3.2, max = 4.0)\r\ndata &lt;- cbind(Bacteroides_A, BMI_A, Bacteroides_B, BMI_B)\r\n\r\n# \u52a0\u8f7d\u5305\uff1a\r\nlibrary(ggplot2)\r\nlibrary(tidyr)\r\n\r\n# \u5bf9\u6570\u636e\u8fdb\u884c\u7b80\u5355\u5904\u7406\uff1a\r\nnew_data &lt;- as.data.frame(rbind(data[1:50, 1:2], data[1:50, 3:4]))\r\ncolnames(new_data) &lt;- c(\"Bacteroides\", \"BMI\")\r\nnew_data$group &lt;- rep(c(\"group_A\", \"group_B\"), c(50, 50))\r\nnew_data$group2 &lt;- rep(paste(\"sample\", 1:50, sep = \"\"), 2)\r\n\r\n# \u6563\u70b9\u56fe\u548c\u4e24\u4e2a\u7bb1\u7ebf\u56fe\u90fd\u5305\u542b\u5728\u540c\u4e00\u4e2a\u56fe\u4e2d\r\nscatter_plot &lt;- ggplot(new_data) +\r\n  geom_point(aes(Bacteroides, BMI, color = group)) +\r\n  scale_color_manual(values = c(group_A = \"#ff00ff\", group_B = \"#8ac53e\")) +\r\n  theme_classic() +\r\n  scale_x_continuous(breaks = seq(-17, -10, 1)) +\r\n  scale_y_continuous(breaks = seq(3.2, 4.2, 0.2)) +\r\n  xlab(\"Bacteroides\") +\r\n  ylab(\"BMI (lg)\") +\r\n  theme(legend.position = 'none')\r\n\r\nleft_boxplot &lt;- ggplot(new_data, aes(group, BMI)) +\r\n  stat_boxplot(geom = \"errorbar\", width = 0.15, aes(color = group)) +\r\n  geom_boxplot(aes(color = group), fill = \"white\") +\r\n  geom_line(aes(group = group2), color = \"black\", linetype = \"dashed\", size = 0.2, alpha = 0.8) +\r\n  geom_jitter(aes(color = group, fill = group), width = 0.05, shape = 21) +\r\n  scale_color_manual(values = c(group_A = \"#ff00ff\", group_B = \"#8ac53e\")) +\r\n  scale_fill_manual(values = c(group_A = \"#ff00ff\", group_B = \"#8ac53e\")) +\r\n  theme_classic() +\r\n  scale_x_discrete(labels = c(\"A\", \"B\")) +\r\n  scale_y_continuous(breaks = seq(3.2, 4.2, 0.2)) +\r\n  xlab(\"\") +\r\n  ylab(\"\") +\r\n  theme(legend.position = 'none')\r\n\r\ndown_boxplot &lt;- ggplot(new_data, aes(group, Bacteroides)) +\r\n  stat_boxplot(geom = \"errorbar\", width = 0.15, aes(color = group)) +\r\n  geom_boxplot(aes(color = group), fill = \"white\") +\r\n  geom_line(aes(group = group2), color = \"black\", linetype = \"dashed\", size = 0.2, alpha = 0.8) +\r\n  geom_jitter(aes(color = group, fill = group), width = 0.05, shape = 21) +\r\n  scale_color_manual(values = c(group_A = \"#ff00ff\", group_B = \"#8ac53e\")) +\r\n  scale_fill_manual(values = c(group_A = \"#ff00ff\", group_B = \"#8ac53e\")) +\r\n  theme_classic() +\r\n  scale_x_discrete(labels = c(\"A\", \"B\")) +\r\n  scale_y_continuous(breaks = seq(-17, -10, 1)) +\r\n  xlab(\"\") +\r\n  ylab(\"\") +\r\n  theme(legend.position = 'none') +\r\n  coord_flip()\r\n\r\n# \u4f7f\u7528gridExtra\u5305\u5c06\u4e09\u4e2a\u56fe\u5408\u5e76\u5230\u4e00\u8d77\r\nlibrary(gridExtra)\r\n\r\n# \u4ee5\u5408\u9002\u7684\u5c3a\u5bf8\u4fdd\u5b58\u7ed8\u56fe\r\ngrid.arrange(scatter_plot, left_boxplot, down_boxplot, ncol = 2, nrow = 2, widths = c(3, 1), heights = c(1, 3))\r\n\r\n# \u4fdd\u5b58\u7ed8\u56fe\r\nggsave(filename = \"combined_plot.pdf\", height = 6, width = 6)\r\n\r\n\r\n<\/code><\/pre>\n<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 bg-gray-50 dark:bg-[#444654]\">\n<div class=\"text-base gap-4 md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap break-words\">\n<div class=\"markdown prose w-full break-words dark:prose-invert dark\">\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-punctuation\"><\/span><\/code><\/div>\n<\/div>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>down_boxplot<\/code>\u7684\u7bb1\u7ebf\u56fe\uff0c\u7ed8\u5236\u4e86<code>Bacteroides<\/code>\u6570\u636e\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>gridExtra<\/code>\u5305\u4e2d\u7684<code>grid.arrange<\/code>\u51fd\u6570\u5c06\u4e09\u4e2a\u56fe\u50cf\uff08\u6563\u70b9\u56fe\u3001\u5de6\u4fa7\u7bb1\u7ebf\u56fe\u548c\u4e0b\u65b9\u7bb1\u7ebf\u56fe\uff09\u7ec4\u5408\u5728\u4e00\u4e2a\u56fe\u50cf\u4e2d\uff0c\u5e76\u8bbe\u7f6e\u4e86\u9002\u5f53\u7684\u5c3a\u5bf8\u3002\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>ggsave<\/code>\u51fd\u6570\u4fdd\u5b58\u5408\u5e76\u540e\u7684\u7ed8\u56fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/yunshangtulv.com.cn\/wp-content\/uploads\/2023\/04\/1682524868238.webp\" \/><\/p>\n<\/div>\n<h2>\u4f18\u5316\u56fe\u7247<\/h2>\n<pre class=\"corepress-code-pre\"><code># \u52a0\u8f7d\u6240\u9700\u7684\u5e93\r\nlibrary(ggplot2)\r\nlibrary(tidyr)\r\nlibrary(gridExtra)\r\nlibrary(cowplot)\r\n\r\n# \u521b\u5efa\u4e00\u4e2a\u65b0\u4e3b\u9898\uff0c\u5220\u9664\u80cc\u666f\u7f51\u683c\u7ebf\uff0c\u5e76\u8c03\u6574\u5750\u6807\u8f74\u6587\u5b57\u5927\u5c0f\r\nmy_theme &lt;- theme_classic() + theme(panel.grid.major = element_blank(),\r\n                                    panel.grid.minor = element_blank(),\r\n                                    axis.text = element_text(size = 12))\r\n\r\n# \u5c06\u6563\u70b9\u56fe\u7684\u56fe\u4f8b\u6dfb\u52a0\u56de\u6765\r\nscatter_plot &lt;- scatter_plot + theme(legend.position = \"right\")\r\n\r\n# \u8c03\u6574\u5de6\u4fa7\u7bb1\u7ebf\u56fe\uff0c\u4f7f\u5176\u66f4\u7a84\uff0c\u540c\u65f6\u5220\u9664y\u8f74\u6807\u7b7e\r\nleft_boxplot &lt;- left_boxplot + my_theme +\r\n  theme(axis.text.y = element_blank(),\r\n        axis.ticks.y = element_blank(),\r\n        axis.title.y = element_blank())\r\n\r\n# \u8c03\u6574\u4e0b\u65b9\u7bb1\u7ebf\u56fe\uff0c\u4f7f\u5176\u66f4\u77ed\uff0c\u540c\u65f6\u5220\u9664x\u8f74\u6807\u7b7e\r\ndown_boxplot &lt;- down_boxplot + my_theme +\r\n  theme(axis.text.x = element_blank(),\r\n        axis.ticks.x = element_blank(),\r\n        axis.title.x = element_blank())\r\n\r\n# \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201ccombined_plot\u201d\u7684\u7ec4\u5408\u56fe\uff0c\u5176\u4e2d\u5305\u542b\u6563\u70b9\u56fe\u3001\u5de6\u4fa7\u7bb1\u7ebf\u56fe\u548c\u4e0b\u65b9\u7bb1\u7ebf\u56fe\r\ncombined_plot &lt;- ggdraw() +\r\n  draw_plot(scatter_plot, x = 0, y = 0, width = 0.75, height = 0.75) +\r\n  draw_plot(left_boxplot, x = 0, y = 0.75, width = 0.75, height = 0.25) +\r\n  draw_plot(down_boxplot, x = 0.75, y = 0, width = 0.25, height = 0.75)\r\n\r\n# \u663e\u793a\u7ec4\u5408\u56fe\r\nprint(combined_plot)\r\n\r\n# \u4fdd\u5b58\u7ec4\u5408\u56fe\r\nggsave(filename = \"further_optimized_combined_plot.pdf\", plot = combined_plot, height = 6, width = 6)\r\n<\/code><\/pre>\n<p>\u5728\u8fd9\u6bb5\u4f18\u5316\u540e\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u4e3b\u9898<code>my_theme<\/code>\uff0c\u7528\u4e8e\u5220\u9664\u80cc\u666f\u7f51\u683c\u7ebf\u5e76\u8c03\u6574\u5750\u6807\u8f74\u6587\u672c\u5927\u5c0f\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u65b0\u4e3b\u9898\u5e94\u7528\u4e8e\u6563\u70b9\u56fe\u3001\u5de6\u4fa7\u7bb1\u7ebf\u56fe\u548c\u4e0b\u65b9\u7bb1\u7ebf\u56fe\uff0c\u5e76\u76f8\u5e94\u5730\u8c03\u6574\u4e86\u5b83\u4eec\u7684\u5c3a\u5bf8\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u76f4\u89c2\u5730\u5c06\u4e09\u4e2a\u56fe\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>cowplot<\/code>\u5305\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>combined_plot<\/code>\u7684\u7ec4\u5408\u56fe\uff0c\u5176\u4e2d\u5305\u542b\u6563\u70b9\u56fe\u3001\u5de6\u4fa7\u7bb1\u7ebf\u56fe\u548c\u4e0b\u65b9\u7bb1\u7ebf\u56fe\u3002\u6211\u4eec\u4f7f\u7528<code>draw_plot<\/code>\u51fd\u6570\u8bbe\u7f6e\u4e86\u6bcf\u4e2a\u5b50\u56fe\u5728\u7ec4\u5408\u56fe\u4e2d\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u663e\u793a\u5e76\u4fdd\u5b58\u4e86\u4f18\u5316\u540e\u7684\u7ec4\u5408\u56fe\u3002\u8fd9\u5c06\u4ea7\u751f\u4e00\u4e2a\u66f4\u7f8e\u89c2\u3001\u6bd4\u4f8b\u5408\u9002\u7684\u56fe\u50cf\uff0c\u540c\u65f6\u4fdd\u6301\u76f4\u89c2\u548c\u7f8e\u89c2\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/yunshangtulv.com.cn\/wp-content\/uploads\/2023\/04\/1682525094178.webp\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u793a\u4f8b\u6570\u636e\u8fdb\u884c\uff0c\u8bf7\u6839\u636e\u5b9e\u9645\u9700\u8981\u8c03\u6574 # \u521b\u5efa\u865a\u62df\u6570\u636e\uff1a Bacteroides_A &lt;- runif( [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=449"}],"version-history":[{"count":0,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"wp:attachment":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}