在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)
: 添加纵向辅助线,限制长度