本文记录了:
- ggplot作图如何设置x轴、y轴标签与x轴、y轴的距离;
- 用于增大x轴、y轴标签与x轴、y轴的距离。
0. 加载【ggplot2】包
library(ggplot2)
1. 示例数据
data <- data.frame(
x = c(1, 2, 3, 4, 5),
y = c(1, 3, 5, 2, 4)
)
2. 默认作图
ggplot(data, aes(x = x, y = y)) +
geom_point()
3. 增大距离后
ggplot(data, aes(x = x, y = y)) +
geom_point() +
theme(axis.title.x = element_text(margin = margin(t = 1, r = 0, b = 0, l = 0, unit = "cm")))+
theme(axis.title.y = element_text(margin = margin(t = 0, r = 1, b = 0, l = 0, unit = "cm")))