or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
快速進行ggplot2繪圖布置-patchwork
tags:
R
ggplot2
可視化
patchwork 利用簡單的數學運算符組合多個ggplot2圖片
允許任意複雜的圖組成
基本應用
+
加號與|
豎線用於水平排版- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →/
除號用於垂直排版- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →()
括弧用於合併圖區- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →控制布局
plot_layout( ncol = NULL, nrow = NULL, byrow = NULL, widths = NULL, heights = NULL, guides = NULL, tag_level = NULL, design = NULL
)
欄列數
plot_layout(ncol = NULL, nrow = NULL )
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →繪圖區大小
plot_layout(widths = NULL, heights = NULL)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →空白繪圖區
plot_spacer()
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →指定排版
plot_layout(design = NULL)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →鑲嵌圖片
inset_element()
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →圖例控制
刪除重複圖例
plot_layout(guides='collect')
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →更改位置
theme(legend.position='bottom')
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →標題與註腳
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →變更標題字體大小
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →添加標籤
plot_annotation(tag_levels = 'A')
類型有'a', 'A', '1', 'i, 'I'
多層次標籤
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →添加對點陣圖形式(如raster類和nativeRaster類)
patchwork最初是為ggplot2設計的
但它一直支持其他圖形類型
比如grobs和基礎圖形(通過使用公式表示法)
在這次更新中,它增加了對另一種類型的支持
點陣圖。點陣圖類(raster class)和原生點陣圖類(nativeRaster class)現在它們可以被直接識別,並且可以通過
wrap_elements()
函數使用在被patchwork匯入的圖形也會成為事是ggplot2的物件
可以使用ggplot2的一些與法修改圖形呈現
例如背景、標題等
利用inset_element()就可以將圖片作為浮水印放到繪圖中
inset_element 函數在 patchwork 包中被用於將一個圖形元素(p)插入到另一個圖形中。
它的主要參數包括:
left, bottom, right, top:這些參數定義了插入圖形的位置和大小,
通常使用“npc”單位(0至1之間的數字),表示在父圖形中的相對位置。
align_to:決定對齊方式,可以是"panel"(默認)、"plot"或"full"。
on_top:布林值,決定圖形是否疊加在頂部。
clip:布林值,用於決定是否剪裁超出範圍的圖形部分。
ignore_tag:布林值,用於決定是否忽略標籤。
刪除重複的座標軸
當多個圖表共享相同的y軸時,為了避免視覺上的混亂
可以移除最右側圖表的軸
當然,通過設定主題來移除它,將相關的主題元素設置為element_blank()
但這樣做可能有些麻煩!
使用
element_blank()
非常簡單這種方法能輕鬆地管理和自定義圖表的軸線顯示
從而使得圖形的整體呈現更加清晰和專業。
也可以選擇只刪除Y座標標題
p1 + p2 + plot_layout(axis_titles = "collect")
若是有使用到
|
豎線用於水平鑲嵌的排版你會發現
plot_layout(axes = "collect")
不起作用官方推薦可以使用
widths
進行排版但我更推薦使用design矩陣的方式
更加直覺且能進行更多變化
ncol 和 nrow:分別定義列數和行數。
byrow:決定布局是按行還是按列填充。
widths 和 heights:用於設定每列或每行的寬度和高度。
guides:控制圖例的顯示方式。
tag_level:設定標籤層次。
axes 和 axis_titles:控制軸線的收集與顯示方式。
design:提供一個更靈活的方式來定義佈局。
最後官方展示了一個不受文字拘束的的排版方式

避免受到過長的軸標籤所影響
p1 / p3
參考資料
全文分享至
https://www.facebook.com/LHB0222/
有疑問想討論的都歡迎於下方留言
喜歡的幫我分享給所有的朋友 \o/
有所錯誤歡迎指教
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →