文章目录
调整坐标轴标题的位置
## 载入包
library(ggplot2)
## 调用ggplot2中的mpg数据集
data('mpg')
## 简单画一张图
ggplot(mpg,aes(manufacturer, cty, color = cyl))+
geom_point(size = 2)
主要通过 theme 中的 axis.title.x 和 axis.title.y 来调整
ggplot(mpg,aes(manufacturer, cty, color = cyl))+
geom_point(size = 2)+
theme(axis.title.x = element_text(margin = margin(t = -0.3,
unit = "cm")),
theme(axis.title.y = element_text(margin = margin(r = -0.3,
unit = "cm")) )
margin 中的 t r b l 分别代表 上 右 下 左 四个方向上调整的距离,unit 为单位
ggplot(mpg,aes(manufacturer, cty, color = cyl))+
geom_point(size = 2)+
theme(axis.title.x = element_text(margin = margin(t = 0.5,
unit = "cm")),
theme(axis.title.y = element_text(margin = margin(r = 0.5,
unit = "cm")) )