geom_abline

简介: geom_abline

Lines: horizontal, vertical, and specified by slope and intercept.

Usage

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)

p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() # Fixed values p + geom_vline(xintercept = 5)

p + geom_vline(xintercept = 1:5)

p + geom_hline(yintercept = 20)

p + geom_abline() # Can't see it - outside the range of the data

p + geom_abline(intercept = 20)


# Calculate slope and intercept of line of best fit coef(lm(mpg ~ wt, data = mtcars))

(Intercept)          wt    37.285126   -5.344472

p + geom_abline(intercept = 37, slope = -5)

# But this is easier to do with geom_smooth: p + geom_smooth(method = "lm", se = FALSE)

# To show different lines in different facets, use aesthetics p <- ggplot(mtcars, aes(mpg, wt)) +  geom_point() +  facet_wrap(~ cyl)

# You can also control other aesthetics ggplot(mtcars, aes(mpg, wt, colour = wt)) +  geom_point() +  geom_hline(aes(yintercept = wt, colour = wt), mean_wt) +  facet_wrap(~ cyl)mean_wt <- data.frame(cyl = c(4, 6, 8), wt = c(2.28, 3.11, 4.00)) p + geom_hline(aes(yintercept = wt), mean_wt)


相关文章
|
12月前
R语言绘制组间比较散点图并自动添加P值信息
查询ggprism包使用时候发现官网给出的一示例图比较常用,这里记录学习一下。
148 3
|
12月前
|
算法 安全 数据挖掘
谈谈转录组测序基础知识及常见问题
转录组学(Transcriptomics),是一门在真整体水平上研究细胞中基因转录的情况及转录调控规律的学科,从RNA水平研究基因的表达情况。转录组测序是通过二代测序平台快速全面地获得某一物种特定细胞或组织在某一状态下的几乎所有的转录本及基因序列,可以用来研究基因表达量、基因功能、结构、可变剪接和预测新的转录本等等。转录组(transcriptome),是指特定生长阶段某组织或细胞内所有转录产物的集合,狭义上指所有mRNA的集合。
1308 0
|
12月前
|
数据可视化
绘图系列|R-VennDiagram包绘制韦恩图
绘图系列|R-VennDiagram包绘制韦恩图
139 0
|
12月前
|
数据可视化
R可视化学习-- (8) 环形柱状图
柱状图可谓是论文最常见的图表了,但有时候这种笔直排列一排的柱状图用腻了, 换种呈现方式(比如拐个弯)也可换个心情嘛,今天就先来介绍俩种构建环形柱状图的方法,分别基于ggplot2和其他的R包来绘制。
175 0
|
12月前
gg.gap包—截断Y轴小能手
截断Y轴往往是我们作柱形图时候,当有一组数据的分布过大或者过小时候需要用到,不截断的话值小的变量信息往往会被掩盖,图片也会不美观,今天介绍俩个方便截断Y轴方法供大家参考。
180 0
|
12月前
|
存储 Go 数据库
R|clusterProfiler-富集分析
R|clusterProfiler-富集分析
274 0
|
12月前
|
Linux
CentOS安装TexLive2023
CentOS安装TexLive2023
250 0
|
12月前
IDA宏定义
IDA宏定义
117 0
|
12月前
|
算法
地震监测系统
地震监测系统
|
12月前
|
应用服务中间件
tomcat获取客户端真实ip
tomcat获取客户端真实ip

热门文章

最新文章