Skip to content

Commit

Permalink
ggplot画图-坐标轴截断
Browse files Browse the repository at this point in the history
  • Loading branch information
ixxmu committed Jan 15, 2025
1 parent b3d48aa commit 970120e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/2025-01/ggplot画图_坐标轴截断.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "ggplot画图-坐标轴截断"
date: 2025-01-15T07:58:28Z
draft: ["false"]
tags: [
"fetched",
"Hub of code"
]
categories: ["Acdemic"]
---
ggplot画图-坐标轴截断 by Hub of code
------
<div><section data-tool="mdnice编辑器" data-website="https://www.mdnice.com"><blockquote data-tool="mdnice编辑器"><p>在画图时,有时候纵坐标的数据相差太大。画出来的图比例不太协调,可以使用ggbreak这个包把纵坐标进行截断后,再在AI里面手动调整一下坐标轴会显得协调一些。</p></blockquote><p data-tool="mdnice编辑器"><img data-imgfileid="100001347" data-ratio="0.47575360419397117" data-src="https://mmbiz.qpic.cn/sz_mmbiz_png/BjvkLMEnqargpnpmibSk1rMpZ9ziaHiavsV1IFRUyMZIybP2DfWbB6udOkQUFoYEXDuUia1BqUzvD5Qib2qKHiagnnrA/640?wx_fmt=png&amp;from=appmsg" data-type="png" data-w="763" src="https://mmbiz.qpic.cn/sz_mmbiz_png/BjvkLMEnqargpnpmibSk1rMpZ9ziaHiavsV1IFRUyMZIybP2DfWbB6udOkQUFoYEXDuUia1BqUzvD5Qib2qKHiagnnrA/640?wx_fmt=png&amp;from=appmsg"></p><h3 data-tool="mdnice编辑器"><span></span>ggbreak对坐标轴进行截断<code>scale_y_break</code><span></span></h3><ul data-tool="mdnice编辑器"><li><section><code>scale</code>参考用于控制刻度线,大小</section></li></ul><pre data-tool="mdnice编辑器"><span></span><code>library(dplyr)<br>library(ggplot2)<br>library(ggbreak)<br><br>df &lt;- data.frame(<br> x = c(<span>'a'</span>,<span>'b'</span>,<span>'c'</span>,<span>'d'</span>,<span>'e'</span>,<span>'f'</span>,<span>'g'</span>,<span>'h'</span>,<span>'i'</span>,<span>'j'</span>), <br> y = c(rnorm(3) + 20, rnorm(3) + 10, rnorm(4) + 50) )<br><br>p1 &lt;- ggplot(df,aes(x,y))+<br> geom_col(aes(fill=x))+<br> theme(legend.position = <span>"none"</span>)+<br> scale_y_continuous(expand = c(0,0))<br>p1<br><br><br>p2&lt;-p1+scale_y_break(c(30,40),<span>#截断位置及范围</span><br> space = 0.3,<span>#间距大小</span><br> scales = 1.5)<span>#上下显示比例,大于1上面比例大,小于1下面比例大</span><br><br>p2<br></code></pre><figure data-tool="mdnice编辑器"><img data-imgfileid="100001346" data-ratio="0.5527777777777778" data-src="https://mmbiz.qpic.cn/sz_mmbiz_png/BjvkLMEnqargpnpmibSk1rMpZ9ziaHiavsV8BrN0R5peOicNgEnAVRWrVBVWicZCWQuHx6a734Cic0oqkZhmibmheQmIQ/640?wx_fmt=png&amp;from=appmsg" data-type="png" data-w="1080" src="https://mmbiz.qpic.cn/sz_mmbiz_png/BjvkLMEnqargpnpmibSk1rMpZ9ziaHiavsV8BrN0R5peOicNgEnAVRWrVBVWicZCWQuHx6a734Cic0oqkZhmibmheQmIQ/640?wx_fmt=png&amp;from=appmsg"><figcaption>示例图</figcaption></figure><p data-tool="mdnice编辑器"><br></p><h3 data-tool="mdnice编辑器"><span></span><code>scale_y_break函数</code>参数说明:<span></span></h3><ul data-tool="mdnice编辑器"><li><section><code>c(30,40)</code>表示在坐标轴30-40区间进行截断</section></li><li><section><code>space</code>表示截断后空白区域的宽度</section></li><li><section><code>scales</code>截断后上下纵坐标长度在图片中所显示的相对比例</section></li></ul><p data-tool="mdnice编辑器"><br></p><h3 data-tool="mdnice编辑器"><span></span>参考:<span></span></h3><ol data-tool="mdnice编辑器"><li><section>https://zhuanlan.zhihu.com/p/388729095</section></li><li><section>https://zhuanlan.zhihu.com/p/558355764</section></li><li><section>https://cran.r-project.org/web/packages/ggbreak/vignettes/ggbreak.html</section></li></ol></section><p><br></p><p><mp-style-type data-value="3"></mp-style-type></p></div>
<hr>
<a href="https://mp.weixin.qq.com/s/xIMlzAT8k2ohG473qJtsBA",target="_blank" rel="noopener noreferrer">原文链接</a>

0 comments on commit 970120e

Please sign in to comment.