我的 y 軸的標題很長,并在其末尾包含數學符號。理想情況下,標題將占據 2 行,頂部顯示“長標題示例”,底部顯示“使用數學運算 (% yr-1)”。如何包裝 y 軸標題?
我已經看到了這個SO question,但是當標題中有數學符號時,我似乎無法讓它作業。
帶有包含數學符號的長標題的示例圖
library(ggplot2)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width))
geom_point(shape = 21, size = 4, aes(fill = factor(Species)))
stat_smooth(method = 'lm', se = F, color = "red")
ylab(expression(Long~Title~Example~with~Mathematical~Operation~("%"~yr^-1)))
xlab("Species")
labs(fill = "Species")
scale_y_continuous(breaks = seq(0,5,1), limits = c(0,5))
scale_x_continuous(breaks = seq(0,8,1), limits = c(0,8))
theme_bw()
theme(panel.grid = element_blank(),
text = element_text(size = 18, color = "black"),
axis.text.x = element_text(size = 18, color = "black"),
axis.text.y = element_text(size = 18, color = 'black'),
legend.title.align = 0.5,
legend.position = c(0.15,0.2))
uj5u.com熱心網友回復:
這是一個潛在的解決方案:
library(ggplot2)
# x axis split over two lines
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width))
geom_point(shape = 21, size = 4, aes(fill = factor(Species)))
stat_smooth(method = 'lm', se = F, color = "red")
ylab(expression(atop(Long~Title~Example,
with~Mathematical~Operation~("%"~yr^"-1"))))
xlab("Species")
labs(fill = "Species")
scale_y_continuous(breaks = seq(0,5,1), limits = c(0,5))
scale_x_continuous(breaks = seq(0,8,1), limits = c(0,8))
theme_bw()
theme(panel.grid = element_blank(),
text = element_text(size = 18, color = "black"),
axis.text.x = element_text(size = 18, color = "black"),
axis.text.y = element_text(size = 18, color = 'black'),
legend.title.align = 0.5,
legend.position = c(0.15,0.2))
#> `geom_smooth()` using formula 'y ~ x'

由reprex 包于 2022-03-14 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/443249.html
上一篇:在水平條形圖中繪制連續分布
