ggplot2: 添加辅助线

在ggplot2画图后,在图中添加辅助线

1. geom_hline() & geom_vline()

1.1 添加横向辅助线

plot()+geom_hline(aes(yintercept = 200), colour="blue", linetype="dashed")

ggplot()+geom_bar(data=kk, aes(x=aa, y=bb), col="gray", stat = "identity")+
  geom_bar(data=hh, aes(x=aa, y=bb), col="blue", stat = "identity")+
  geom_hline(aes(yintercept=200), colour="blue", linetype="dashed")  '#添加横向辅助线,示例一
示例一

1.2 添加纵向辅助线

plot()+geom_vline(aes(xintercept = 200), colour="blue", linetype="dashed")

ggplot()+geom_bar(data=kk, aes(x=aa, y=bb), col="gray", stat = "identity")+
  geom_bar(data=hh, aes(x=aa, y=bb), col="blue", stat = "identity")+
  geom_vline(aes(xintercept=2500), colour="red", linetype="dashed")  '#添加横向辅助线,示例二
示例二

2. geom_abline()

plot()+geom_abline(intercept=, slope=, col=, linetype="dashed")

intercept: 截距
slope: 斜率

ggplot()+geom_bar(data=kk, aes(x=aa, y=bb), col="gray", stat = "identity")+
  geom_bar(data=hh, aes(x=aa, y=bb), col="blue", stat = "identity")+
  geom_abline(intercept=400, slope=-7.447e-02, colour="red", linetype="dashed")  '#添加具有倾斜角度的辅助线,可以用来画点图拟合出来的直线,示例三
示例三

geom_segment(aes(x = 0, xend = up_cutoff, y = down_cutoff, yend = down_cutoff),colour = "blue", linetype = "dashed", size = 0.8): 添加横向辅助线,限制长度

geom_segment(aes(x = up_cutoff, xend = up_cutoff, y = 0, yend = down_cutoff),colour = "blue", linetype = "dashed", size = 0.8): 添加纵向辅助线,限制长度

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 作者:严涛浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源 ggplot2学习笔记之图...
    Dylan的迪阅读 2,691评论 0 6
  • 写在前面 ggplot2 是一个功能强大且灵活的R包 ,由Hadley Wickham 编写,其用于生成优雅的图...
    Boer223阅读 28,290评论 0 67
  • 问题: 在R中,该如何在图中加入各种辅助线? 指南: 本节我们将以各种不同的数据图表为例,具体说明这类问题。 横轴...
    Datartisan数据工匠阅读 4,174评论 0 2
  • 简介 文章较长,点击直达我的博客,浏览效果更好。本文内容基本是来源于STHDA,这是一份十分详细的ggplot2使...
    taoyan阅读 51,431评论 7 159
  • 前言 ggplot2 包含很多绘制线条的函数:大致可分为如下几类: 连接线:折线(geom_line)、路径线(g...
    名本无名阅读 7,841评论 0 9