Jeason
419字约1分钟
2020-09-22
添加竖线或者横线
geom_abline(mapping = NULL, data = NULL, ..., slope, intercept, na.rm = FALSE, show.legend = NA)
geom_hline(mapping = NULL, data = NULL, ..., yintercept, na.rm = FALSE, show.legend = NA)
geom_vline(mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE, show.legend = NA)
三个函数的作用分别是,geom_abline添加斜线, geom_hline添加水平线,geom_vline添加垂直线
参数slope 表示斜率 intercept表示截距
参数yintercept 表示y轴截距或直线所在位置
参数xintercept 表示x轴截距或直线所在位置
添加线段
geom_segment(aes(x = x1, y = y1, xend = x2, yend = y2)
x, y控制线段起始位置,xend,yend控制线段终止位置
去掉网格
theme(panel.grid = element_blank())
使用与plot相似的背景
theme_classic()
x,y轴转换
coord_flip()
去掉图形和坐标轴间隙
scale_y_continuous(expand = c(0,0))//这个可以去掉与X轴间隙
scale_x_continuous(expand = c(0,0))//这个可以去掉与Y轴间隙
geom_ribbon(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, orientation = NA,
show.legend = NA, inherit.aes = TRUE,outline.type = "both")
geom_area(mapping = NULL, data = NULL, stat = "identity", position = "stack", na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE, ..., outline.type = "upper")
添加箭头或线段需要使用 annotate('segment')
annotate('segment', x=#, xend=#, y=#, yend=#, arrow=arrow())
arrow
参数时是绘制线段arrow
参数,需要提前加载 library(grid)
包才能调用 arrow()
函数theme(plot.title = element_text(hjust = 0.5))