我試圖從三個單獨的圖(見圖片)制作一個多面板圖。但是,當圖是多面板格式時,我無法糾正成束的 x 軸刻度標簽。以下是單個圖和多面板的腳本:
個人情節:
NewDat [[60]]
EstRes <- NewDat [[60]]
EstResPlt = ggplot(EstRes,aes(Distance3, `newBa`)) geom_line() scale_x_continuous(n.breaks = 10, limits = c(0, 3500)) scale_y_continuous(n.breaks = 10, limits = c(0,25)) xlab("Distance from Core (μm)") ylab("Ba:Ca concentration(μmol:mol)") geom_hline(yintercept=2.25, linetype="dashed", color = "red") geom_vline(xintercept = 1193.9, linetype="dashed", color = "grey") geom_vline(xintercept = 1965.5, linetype="dashed", color = "grey") geom_vline(xintercept = 2616.9, linetype="dashed", color = "grey") geom_vline(xintercept = 3202.8, linetype="dashed", color = "grey") geom_vline(xintercept = 3698.9, linetype="dashed", color = "grey")
EstResPlt
多面板圖:
MultiP <- grid.arrange(MigrPlt,OcResPlt,EstResPlt, nrow =1)
我試圖包括:
MultiP <- grid.arrange(MigrPlt,OcResPlt,EstResPlt, nrow =1)
theme(axis.text.x = element_text (angle = 45)) )
MultiP
但只收到錯誤。沒有必要包含所有刻度線。初始值、中間值和最終值就足夠了,因此不需要將它們都包括在內或成角度。我只是不知道該怎么做。將不勝感激。

uj5u.com熱心網友回復:
有幾個選項可以解決擁擠的軸。讓我們考慮以下與您的情況相似的示例。默認標簽策略不會使 x 軸過度擁擠。
library(ggplot2)
library(patchwork)
library(scales)
df <- data.frame(
x = seq(0, 3200, by = 20),
y = cumsum(rnorm(161))
)
p <- ggplot(df, aes(x, y))
geom_line()
(p p p) / p &
scale_x_continuous(
name = "Distance (um)"
)

然而,因為你已經給n.breaks = 10了秤,它變得擁擠。所以一個簡單的解決方案就是洗掉它。
(p p p) / p &
scale_x_continuous(
n.breaks = 10,
name = "Distance (um)"
)

或者,您可以將微米轉換為毫米,這樣標簽的寬度就會變小。
(p p p) / p &
scale_x_continuous(
n.breaks = 10,
labels = label_number(scale = 1e-3, accuracy = 0.1),
name = "Distance (mm)"
)

另一種替代方法是僅對每個n單位進行中斷,在下面的情況下,為 1000。這恰好與偶然忽略相吻合n.breaks = 10。
(p p p) / p &
scale_x_continuous(
breaks = breaks_width(1000),
name = "Distance (um)"
)

由
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/345868.html
