{"id":7652,"date":"2024-07-11T20:01:01","date_gmt":"2024-07-11T12:01:01","guid":{"rendered":""},"modified":"2024-07-11T20:01:01","modified_gmt":"2024-07-11T12:01:01","slug":"\u795e\u5668\uff01\u4f7f\u7528 patchworklib \u5e93\u8fdb\u884c\u591a\u56fe\u6392\u7248\u771f\u68d2\u554a","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7652.html","title":{"rendered":"\u795e\u5668\uff01\u4f7f\u7528 patchworklib \u5e93\u8fdb\u884c\u591a\u56fe\u6392\u7248\u771f\u68d2\u554a"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u5982\u679c\u60f3\u628a\u591a\u4e2a\u56fe\u5408\u5e76\u653e\u5728\u4e00\u4e2a\u56fe\u91cc\uff0c\u5982\u56fe\uff0c\u8be5\u5982\u4f55\u5b9e\u73b0
\"\u795e\u5668\uff01\u4f7f\u7528
\u597d\u5728R\u8bed\u8a00 \u548c Python \u90fd\u6709\u5bf9\u5e94\u7684\u89e3\u51b3\u65b9\u6848\uff0c \u5206\u522b\u662fpatchwork\u5305\u548cpatchworklib\u5e93\u3002<\/p>\n

\u63a8\u4ecb1<\/h3>\n

\u6211\u4eec\u6253\u9020\u4e86\u300a100\u4e2a\u8d85\u5f3a\u7b97\u6cd5\u6a21\u578b\u300b\uff0c\u7279\u70b9\uff1a\u4ece0\u52301\u8f7b\u677e\u5b66\u4e60\uff0c\u539f\u7406\u3001\u4ee3\u7801\u3001\u6848\u4f8b\u5e94\u6709\u5c3d\u6709\uff0c\u6240\u6709\u7684\u7b97\u6cd5\u6a21\u578b\u90fd\u662f\u6309\u7167\u8fd9\u6837\u7684\u8282\u594f\u8fdb\u884c\u8868\u8ff0\uff0c\u6240\u4ee5\u662f\u4e00\u5957\u5b8c\u5b8c\u6574\u6574\u7684\u6848\u4f8b\u5e93\u3002<\/p>\n

\u5f88\u591a\u521d\u5b66\u8005\u662f\u6709\u8fd9\u4e48\u4e00\u4e2a\u75db\u70b9\uff0c\u5c31\u662f\u6848\u4f8b\uff0c\u6848\u4f8b\u7684\u5b8c\u6574\u6027\u76f4\u63a5\u5f71\u54cd\u540c\u5b66\u7684\u5174\u81f4\u3002\u56e0\u6b64\uff0c\u6211\u6574\u7406\u4e86 100\u4e2a\u6700\u5e38\u89c1\u7684\u7b97\u6cd5\u6a21\u578b\uff0c\u5728\u4f60\u7684\u5b66\u4e60\u8def\u4e0a\u52a9\u63a8\u4e00\u628a\uff01<\/p>\n

\u5982\u679c\u4f60\u4e5f\u60f3\u5b66\u4e60\u4ea4\u6d41\uff0c\u8d44\u6599\u83b7\u53d6\uff0c\u5747\u53ef\u52a0\u4ea4\u6d41\u7fa4\u83b7\u53d6\uff0c\u6dfb\u52a0\u65f6\u6700\u597d\u7684\u5907\u6ce8\u65b9\u5f0f\u4e3a\uff1a\u6765\u6e90+\u5174\u8da3\u65b9\u5411\uff0c\u65b9\u4fbf\u627e\u5230\u5fd7\u540c\u9053\u5408\u7684\u670b\u53cb\u3002<\/p>\n

\n

\u65b9\u5f0f\u2460\u3001\u6dfb\u52a0\u5fae\u4fe1\u53f7\uff1adkl88194\uff0c\u5907\u6ce8\uff1a\u6765\u81eaCSDN + \u4ea4\u6d41\u7fa4
\u65b9\u5f0f\u2461\u3001\u5fae\u4fe1\u641c\u7d22\u516c\u4f17\u53f7\uff1aPython\u5b66\u4e60\u4e0e\u6570\u636e\u6316\u6398\uff0c\u540e\u53f0\u56de\u590d\uff1a\u4ea4\u6d41\u7fa4<\/p>\n<\/blockquote>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

\u63a8\u4ecb2<\/h3>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

R\u8bed\u8a00<\/h3>\n

\u5b89\u88c5<\/p>\n

# install.packages(\"devtools\") devtools::install_github(\"thomasp85\/patchwork\") <\/code><\/pre>\n

\u4e24\u4e2a\u56fe\u5e76\u6392\u5728\u4e00\u884c\uff0c\u53ea\u9700\u8981\u5bfc\u5165patchwork\uff0c \u7136\u540e\u76f8\u52a0\u5373\u53ef<\/p>\n

library(ggplot2) library(patchwork) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp)) p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + p2 <\/code><\/pre>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

\u4e24\u884c\uff0c\u7b2c\u4e00\u884c\u4e09\u4e2a\u56fe\uff0c\u7b2c\u4e8c\u884c\u4e00\u4e2a\u56fe<\/p>\n

p3 <- ggplot(mtcars) + geom_smooth(aes(disp, qsec)) p4 <- ggplot(mtcars) + geom_bar(aes(carb)) (p1 | p2 | p3) \/ p4 <\/code><\/pre>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

\u4e09\u3001Python<\/h3>\n

Patchworklib \u662f\u4e0e matplotlib \u76f8\u5173\u7684\u7ed8\u56fe\uff08\u7b80\u5355 matplotlib \u7ed8\u56fe\u3001Seaborn \u7ed8\u56fe\uff08\u8f74\u7ea7\u548c\u56fe\u5f62\u7ea7\uff09\u548cplotnine \u7ed8\u56fe\uff09\u7684\u901a\u7528\u7f16\u8f91\u5668\u3002\u8fd9\u4e2a\u5e93\u7684\u7075\u611f\u6765\u81ea\u4e8e ggplot2 \u7684patchwork\u3002\u56e0\u6b64\uff0c\u4f5c\u4e3a\u539f\u59cb\u62fc\u51d1\uff0c\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5730\u4ec5\u4f7f\u7528 \/<\/code>\u548c |<\/code> \u5bf9\u9f50 matplotlib \u56fe\u3002<\/p>\n

Patchworklib \u63d0\u4f9b\u4e86\u8be5\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u3002\u901a\u8fc7\u4f7f\u7528 patchworklib\uff0c\u4efb\u4f55\u7c7b\u578b\u7684seaborn \u548cplotnine \u56fe\u90fd\u53ef\u4ee5\u4f5c\u4e3amatplotlib \u5b50\u56fe\u8fdb\u884c\u5904\u7406\u3002\u5b89\u88c5<\/p>\n

pip3 install<\/span> patchworklib <\/code><\/pre>\n
import<\/span> patchworklib as<\/span> pw import<\/span> seaborn as<\/span> sns fmri =<\/span> sns.<\/span>load_dataset(<\/span>\"fmri\"<\/span>)<\/span> ax1 =<\/span> pw.<\/span>Brick(<\/span>figsize=<\/span>(<\/span>3<\/span>,<\/span>2<\/span>)<\/span>)<\/span> sns.<\/span>lineplot(<\/span>x=<\/span>\"timepoint\"<\/span>,<\/span> y=<\/span>\"signal\"<\/span>,<\/span> hue=<\/span>\"region\"<\/span>,<\/span> style=<\/span>\"event\"<\/span>,<\/span> data=<\/span>fmri,<\/span> ax=<\/span>ax1)<\/span> ax1.<\/span>legend(<\/span>bbox_to_anchor=<\/span>(<\/span>1.05<\/span>,<\/span> 1.0<\/span>)<\/span>,<\/span> loc=<\/span>'upper left'<\/span>)<\/span> ax1.<\/span>set_title(<\/span>\"ax1\"<\/span>)<\/span> titanic =<\/span> sns.<\/span>load_dataset(<\/span>\"titanic\"<\/span>)<\/span> ax2 =<\/span> pw.<\/span>Brick(<\/span>figsize=<\/span>(<\/span>1<\/span>,<\/span>2<\/span>)<\/span>)<\/span> sns.<\/span>barplot(<\/span>x=<\/span>\"sex\"<\/span>,<\/span> y=<\/span>\"survived\"<\/span>,<\/span> hue=<\/span>\"class\"<\/span>,<\/span> data=<\/span>titanic,<\/span> ax=<\/span>ax2)<\/span> ax2.<\/span>move_legend(<\/span>new_loc=<\/span>'upper left'<\/span>,<\/span> bbox_to_anchor=<\/span>(<\/span>1.05<\/span>,<\/span> 1.0<\/span>)<\/span>)<\/span> ax2.<\/span>set_title(<\/span>\"ax2\"<\/span>)<\/span> ax12 =<\/span> ax1|<\/span>ax2 ax12.<\/span>savefig(<\/span>\"ax12.png\"<\/span>)<\/span> <\/code><\/pre>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

#\u7701\u7565 ax1\u3001ax2\u3001ax4\u7ed8\u5236\u8fc7\u7a0b<\/span> ax124 =<\/span> ax1|<\/span>ax2|<\/span>ax4 ax124.<\/span>savefig(<\/span>\"..\/img\/ax124.png\"<\/span>)<\/span> <\/code><\/pre>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n

#\u7701\u7565 ax124\u3001ax3\u3001ax5\u7ed8\u5236\u8fc7\u7a0b<\/span> ax12435 =<\/span> ax124\/<\/span>(<\/span>ax3|<\/span>ax5)<\/span> ax12435.<\/span>savefig(<\/span>\"..\/img\/ax12435.png\"<\/span>)<\/span> <\/code><\/pre>\n

\"\u795e\u5668\uff01\u4f7f\u7528<\/p>\n","protected":false},"excerpt":{"rendered":"\u795e\u5668\uff01\u4f7f\u7528 patchworklib \u5e93\u8fdb\u884c\u591a\u56fe\u6392\u7248\u771f\u68d2\u554a\u5982\u679c\u60f3\u628a\u591a\u4e2a\u56fe\u5408\u5e76\u653e\u5728\u4e00\u4e2a\u56fe\u91cc\uff0c\u5982\u56fe\uff0c\u8be5\u5982\u4f55\u5b9e\u73b0\u597d\u5728R\u8bed\u8a00\u548cPython\u90fd\u6709\u5bf9\u5e94...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7652"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7652"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7652\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}