{"id":180560,"date":"2024-05-08T20:37:51","date_gmt":"2024-05-08T12:37:51","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/180560.html"},"modified":"2024-05-08T20:37:56","modified_gmt":"2024-05-08T12:37:56","slug":"r%e8%af%ad%e8%a8%80%e5%9c%a8markdown%e9%87%8c%e8%bf%90%e7%94%a8qplot%e7%9a%84%e6%95%a3%e7%82%b9%e5%9b%be%e5%a6%82%e4%bd%95%e6%94%be%e7%bd%ae%e5%9c%a8%e4%b8%80%e8%b5%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/180560.html","title":{"rendered":"r\u8bed\u8a00\u5728markdown\u91cc\u8fd0\u7528qplot\u7684\u6563\u70b9\u56fe\u5982\u4f55\u653e\u7f6e\u5728\u4e00\u8d77"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27065816\/243ee68f-0ff6-468f-a0d6-634e5ab5588c.webp\" alt=\"r\u8bed\u8a00\u5728markdown\u91cc\u8fd0\u7528qplot\u7684\u6563\u70b9\u56fe\u5982\u4f55\u653e\u7f6e\u5728\u4e00\u8d77\" \/><\/p>\n<p><p>\u5728R\u8bed\u8a00\u4e2d\u4f7f\u7528<code>markdown<\/code>\u8fdb\u884c\u6587\u6863\u7f16\u5199\u65f6\uff0c\u5229\u7528<code>ggplot2<\/code>\u5305\u4e2d\u7684<code>qplot<\/code>\u51fd\u6570\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u9ad8\u8d28\u91cf\u7684\u6563\u70b9\u56fe\u3002\u8981\u5c06\u4e0d\u540c\u7684\u6563\u70b9\u56fe\u653e\u7f6e\u5728\u4e00\u9875\u9762\u4e0a\u5c55\u793a\u3001<strong>\u5408\u7406\u5e03\u5c40<\/strong>\u548c<strong>\u4fdd\u6301\u56fe\u8868\u7f8e\u89c2<\/strong>\u662f\u5173\u952e\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<strong>\u5229\u7528<code>gridExtra<\/code>\u5305\u4e2d\u7684<code>grid.arrange<\/code>\u51fd\u6570<\/strong>\u6765\u5b9e\u73b0\u4e0d\u540c\u6563\u70b9\u56fe\u7684\u5e76\u6392\u5c55\u793a\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u7075\u6d3b\u63a7\u5236\u6bcf\u4e2a\u56fe\u8868\u7684\u5e03\u5c40\uff0c\u8fd8\u80fd\u4fdd\u8bc1\u5728Markdown\u6587\u6863\u4e2d\u7684\u8f93\u51fa\u7ed3\u679c\u65e2\u6574\u6d01\u53c8\u5177\u6709\u8f83\u9ad8\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u4e0e\u52a0\u8f7d\u5fc5\u8981\u5305<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6563\u70b9\u56fe\u7ed8\u5236\u548c\u5e03\u5c40\u524d\uff0c\u9996\u5148\u786e\u4fdd\u5b89\u88c5\u4e86<code>ggplot2<\/code>\u548c<code>gridExtra<\/code>\u4e24\u4e2a\u5305\u3002<code>ggplot2<\/code>\u7528\u4e8e\u521b\u5efa\u6563\u70b9\u56fe\uff0c\u800c<code>gridExtra<\/code>\u5e2e\u52a9\u6211\u4eec\u5728Markdown\u4e2d\u4ee5\u5408\u9002\u7684\u5e03\u5c40\u5c55\u793a\u8fd9\u4e9b\u56fe\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u5b89\u88c5\u5305<\/p>\n<p>install.packages(&quot;ggplot2&quot;)<\/p>\n<p>install.packages(&quot;gridExtra&quot;)<\/p>\n<h2><strong>\u52a0\u8f7d\u5305<\/strong><\/h2>\n<p>library(ggplot2)<\/p>\n<p>library(gridExtra)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u521b\u5efa\u6563\u70b9\u56fe<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528<code>qplot<\/code>\u51fd\u6570\u521b\u5efa\u51e0\u4e2a\u7b80\u5355\u7684\u6563\u70b9\u56fe\u3002<code>qplot<\/code>\u662f<code>ggplot2<\/code>\u7684\u5feb\u901f\u7ed8\u56fe\u51fd\u6570\uff0c\u9002\u5408\u4e8e\u5feb\u901f\u5236\u4f5c\u56fe\u8868\u5e76\u8fdb\u884c\u521d\u6b65\u7684\u6570\u636e\u63a2\u7d22\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u521b\u5efa\u6563\u70b9\u56fe<\/p>\n<p>qplot1 &lt;- qplot(data=mtcars, x=wt, y=mpg)<\/p>\n<p>qplot2 &lt;- qplot(data=mtcars, x=wt, y=qsec)<\/p>\n<p>qplot3 &lt;- qplot(data=mtcars, x=wt, y=hp)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4ee5<code>mtcars<\/code>\u6570\u636e\u96c6\u4e3a\u4f8b\uff0c\u521b\u5efa\u4e86\u4e09\u4e2a\u4e0d\u540c\u7684\u6563\u70b9\u56fe\uff0c\u5206\u522b\u5c55\u793a\u4e86\u6c7d\u8f66\u7684\u91cd\u91cf\u4e0e\u6cb9\u8017\u3001\u56db\u5206\u4e4b\u4e00\u82f1\u91cc\u8017\u65f6\u3001\u4ee5\u53ca\u9a6c\u529b\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5229\u7528<code>GRIDEXTRA<\/code>\u5305\u8fdb\u884c\u5e03\u5c40<\/h3>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u4f7f\u7528<code>gridExtra<\/code>\u5305\u4e2d\u7684<code>grid.arrange<\/code>\u51fd\u6570\u5c06\u521b\u5efa\u7684\u6563\u70b9\u56fe\u653e\u7f6e\u5728\u4e00\u8d77\u3002\u6b64\u51fd\u6570\u975e\u5e38\u7075\u6d3b\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\u56fe\u8868\u7684\u5e03\u5c40\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u5c06\u6563\u70b9\u56fe\u653e\u7f6e\u5728\u4e00\u8d77<\/p>\n<p>grid.arrange(qplot1, qplot2, qplot3, ncol=3)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8bbe\u7f6e<code>ncol<\/code>\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u63a7\u5236\u5e76\u6392\u5c55\u793a\u7684\u56fe\u8868\u6570\u91cf\u3002\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>ncol=3<\/code>\u610f\u5473\u7740\u4e09\u4e2a\u6563\u70b9\u56fe\u5c06\u5e76\u6392\u5c55\u793a\u5728\u4e00\u884c\u4e0a\u3002\u5229\u7528<code>grid.arrange<\/code>\u51fd\u6570\u4e0d\u4ec5\u53ef\u4ee5\u8bbe\u7f6e\u5e76\u6392\u7684\u5217\u6570\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7<code>nrow<\/code>\u53c2\u6570\u6765\u8bbe\u5b9a\u884c\u6570\uff0c\u5b9e\u73b0\u66f4\u4e3a\u590d\u6742\u7684\u5e03\u5c40\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8c03\u6574\u6563\u70b9\u56fe\u7ec6\u8282<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u4f7f\u6563\u70b9\u56fe\u66f4\u52a0\u7f8e\u89c2\u548c\u4fe1\u606f\u4e30\u5bcc\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u8c03\u6574\u5176\u7ec6\u8282\uff0c\u5982\u8bbe\u7f6e\u6807\u9898\u3001\u8f74\u6807\u7b7e\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-R\"># \u8bbe\u7f6e\u6563\u70b9\u56fe\u7ec6\u8282<\/p>\n<p>qplot1 + ggtitle(&quot;Weight vs MPG&quot;) + xlab(&quot;Weight&quot;) + ylab(&quot;Miles\/(US) gallon&quot;)<\/p>\n<p>qplot2 + ggtitle(&quot;Weight vs QSEC&quot;) + xlab(&quot;Weight&quot;) + ylab(&quot;1\/4 mile time&quot;)<\/p>\n<p>qplot3 + ggtitle(&quot;Weight vs HP&quot;) + xlab(&quot;Weight&quot;) + ylab(&quot;Horsepower&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6dfb\u52a0<code>ggtitle<\/code>\u3001<code>xlab<\/code>\u3001\u548c<code>ylab<\/code>\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a\u5404\u4e2a\u6563\u70b9\u56fe\u5206\u522b\u8bbe\u7f6e\u6807\u9898\u548c\u8f74\u6807\u7b7e\uff0c\u4f7f\u5f97\u6bcf\u4e2a\u56fe\u8868\u6240\u8868\u8fbe\u7684\u4fe1\u606f\u66f4\u4e3a\u51c6\u786e\u548c\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u5c06R\u8bed\u8a00\u4e2d<code>markdown<\/code>\u4e2d\u7684<code>qplot<\/code>\u6563\u70b9\u56fe\u653e\u5728\u4e00\u8d77\uff0c\u4e0d\u4ec5\u9700\u8981\u6ce8\u610f\u56fe\u8868\u7684\u521b\u5efa\u548c\u6570\u636e\u7684\u5448\u73b0\uff0c\u66f4\u91cd\u8981\u7684\u662f\u5408\u7406\u5b89\u6392\u5e03\u5c40\u548c\u4f18\u5316\u56fe\u8868\u7ec6\u8282\u3002\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7075\u6d3b\u9ad8\u6548\u5730\u5728Markdown\u6587\u6863\u4e2d\u5c55\u793a\u591a\u4e2a\u9ad8\u8d28\u91cf\u7684\u6563\u70b9\u56fe\uff0c\u5e76\u4f7f\u5176\u5e03\u5c40\u7f8e\u89c2\u3001\u4fe1\u606f\u6e05\u6670\uff0c\u6781\u5927\u5730\u589e\u5f3a\u4e86\u6570\u636e\u53ef\u89c6\u5316\u7684\u8868\u73b0\u529b\u548c\u9605\u8bfb\u4f53\u9a8c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u95ee\u98981\uff1a<\/strong>\u5982\u4f55\u5728Markdown\u4e2d\u540c\u65f6\u663e\u793a\u591a\u4e2aR\u8bed\u8a00\u7684\u6563\u70b9\u56fe\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong>\u8981\u5728Markdown\u4e2d\u540c\u65f6\u663e\u793a\u591a\u4e2aR\u8bed\u8a00\u7684\u6563\u70b9\u56fe\uff0c\u53ef\u4ee5\u4f7f\u7528R\u8bed\u8a00\u7684qplot\u51fd\u6570\u7ed3\u5408Markdown\u7684\u4ee3\u7801\u5757\u529f\u80fd\u3002\u9996\u5148\uff0c\u901a\u8fc7R\u4ee3\u7801\u751f\u6210\u7b2c\u4e00\u4e2a\u6563\u70b9\u56fe\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a\u53d8\u91cf\u3002\u7136\u540e\uff0c\u5728Markdown\u4e2d\u4f7f\u7528\u4e24\u4e2a\u6216\u591a\u4e2a\u4ee3\u7801\u5757\uff0c\u5206\u522b\u751f\u6210\u5e76\u663e\u793a\u6bcf\u4e2a\u6563\u70b9\u56fe\u3002\u53ef\u4ee5\u4f7f\u7528Markdown\u7684\u6392\u7248\u8bed\u6cd5\u548c\u5e03\u5c40\u529f\u80fd\u5c06\u591a\u4e2a\u6563\u70b9\u56fe\u5e76\u6392\u653e\u7f6e\u5728\u4e00\u8d77\u3002<\/p>\n<p><strong>\u95ee\u98982\uff1a<\/strong>\u6709\u6ca1\u6709\u793a\u4f8b\u4ee3\u7801\u6765\u663e\u793a\u591a\u4e2aR\u8bed\u8a00\u6563\u70b9\u56fe\u7684\u6392\u5217\u65b9\u5f0f\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong>\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\u6765\u5c55\u793a\u5982\u4f55\u5728Markdown\u4e2d\u653e\u7f6e\u591a\u4e2aR\u8bed\u8a00\u6563\u70b9\u56fe\uff1a<\/p>\n<pre><code class=\"language-r\"># \u751f\u6210\u7b2c\u4e00\u4e2a\u6563\u70b9\u56fe\nscatter_plot1 &lt;- qplot(x, y, data = df1, geom = &quot;point&quot;)\n\n# \u751f\u6210\u7b2c\u4e8c\u4e2a\u6563\u70b9\u56fe\nscatter_plot2 &lt;- qplot(x, y, data = df2, geom = &quot;point&quot;)\n\n# \u5728Markdown\u4e2d\u663e\u793a\u591a\u4e2a\u6563\u70b9\u56fe\n<\/code><\/pre>\n<pre><code class=\"language-{r\">scatter_plot1\n<\/code><\/pre>\n<pre><code class=\"language-{r\">scatter_plot2\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u9996\u5148\u4f7f\u7528qplot\u51fd\u6570\u751f\u6210\u4e86\u4e24\u4e2a\u6563\u70b9\u56fe\uff0c\u5e76\u5c06\u5b83\u4eec\u4fdd\u5b58\u5728scatter_plot1\u548cscatter_plot2\u8fd9\u4e24\u4e2a\u53d8\u91cf\u4e2d\u3002\u7136\u540e\uff0c\u5728Markdown\u4e2d\u4f7f\u7528\u4ee3\u7801\u5757\u8bed\u6cd5\uff0c\u5728\u6bcf\u4e2a\u4ee3\u7801\u5757\u4e2d\u663e\u793a\u4e00\u4e2a\u6563\u70b9\u56fe\u3002\u901a\u8fc7\u8bbe\u7f6efig.width\u548cfig.height\u53c2\u6570\uff0c\u53ef\u4ee5\u8c03\u6574\u6563\u70b9\u56fe\u7684\u5927\u5c0f\u3002<\/p>\n<p><strong>\u95ee\u98983\uff1a<\/strong>\u9664\u4e86\u6392\u5217\u65b9\u5f0f\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5728Markdown\u4e2d\u540c\u65f6\u5c55\u793a\u591a\u4e2aR\u8bed\u8a00\u6563\u70b9\u56fe\u5417\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong>\u662f\u7684\uff0c\u9664\u4e86\u6392\u5217\u65b9\u5f0f\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Markdown\u4e2d\u7684\u8868\u683c\u6216\u7f51\u683c\u5e03\u5c40\u529f\u80fd\u6765\u540c\u65f6\u5c55\u793a\u591a\u4e2aR\u8bed\u8a00\u6563\u70b9\u56fe\u3002\u53ef\u4ee5\u5c06\u591a\u4e2a\u6563\u70b9\u56fe\u4fdd\u5b58\u4e3a\u5355\u72ec\u7684\u56fe\u7247\u6587\u4ef6\uff0c\u5728Markdown\u4e2d\u4f7f\u7528\u56fe\u50cf\u6807\u7b7e<code>&lt;img&gt;<\/code>\u5c06\u5b83\u4eec\u5d4c\u5165\u5230\u8868\u683c\u6216\u7f51\u683c\u5e03\u5c40\u4e2d\u3002\u53e6\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528R\u8bed\u8a00\u7684gridExtra\u5305\u6216ggplot2\u5305\u4e2d\u7684facet\u529f\u80fd\u6765\u5728\u4e00\u4e2a\u56fe\u5f62\u4e2d\u5c55\u793a\u591a\u4e2a\u6563\u70b9\u56fe\u3002\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u7531\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728R\u8bed\u8a00\u4e2d\u4f7f\u7528markdown\u8fdb\u884c\u6587\u6863\u7f16\u5199\u65f6\uff0c\u5229\u7528ggplot2\u5305\u4e2d\u7684qplot\u51fd\u6570\u53ef\u4ee5\u5feb\u901f\u521b\u5efa\u9ad8\u8d28\u91cf\u7684\u6563\u70b9\u56fe [&hellip;]","protected":false},"author":3,"featured_media":180565,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180560"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=180560"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180560\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/180565"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=180560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=180560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=180560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}