如何在限制区域内画直线? [英] How to draw straight lines in a restrictive area?

查看:108
本文介绍了如何在限制区域内画直线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条带有2条直线的光谱图,是使用以下命令绘制的: (a是频谱左边的斜率,b是右边的斜率.此处的边界是3200 Hz)

I have a spectral plot with 2 straight lines, which I made with the following commands: (a is the slope from the left part of the spectrum, b the right. the boundary is 3200 Hz here)

a=0.009909
b=-0.003873

plot(spec, type="l", main...)

abline(a, col="orange")
abline(b, col="skyblue")
abline(v=3200, lty=2)

我想做的是绘制橙色线直到3200 Hz,然后从3200 Hz画出天蓝色线,如下图所示(大致由photoshop创建,对不起):

What I would like to do is to draw the orange line until 3200 Hz and the skyblue line from 3200 Hz like the following plot (roughly created by photoshop, sorry):

使用abline()函数可以吗?还是有什么方法可以做到?

Is that with the function abline() possible? Or is there any way to do that?

非常感谢您!

推荐答案

已修改以纠正错误

这是一个基本示例,应该可以扩展到您的数据.它依赖于首先使用glm为每个数据子集生成最适合的行的系数,然后在lines语句中调用它们.

Here is a basic example that should be extendable to your data. It relies on generating the coefficients for the lines of best fit for each subset of data first using glm and then calling these in a lines statement.

test <- c(1.4, 2.3, 3.8, 3.6, 5.9, 5.4, 7.6, 7.4, 8.1, 8.7, 7.4, 6.9, 
5.4, 4.7, 2.7, 1.8, 1.1)

plot(test,type="l",ylim=c(0,12))
fit1 <- glm(test[1:8] ~ I(1:8))
fit2 <- glm(test[9:17] ~ I(1:9))

# ...$coefficients[2] is the slope, ...$coefficients[1] is the intercept
lines(1:9, 1:9 * fit1$coefficients[2] + fit1$coefficients[1],col="red")
lines(9:17,1:9 * fit2$coefficients[2] + fit2$coefficients[1],col="blue")

这篇关于如何在限制区域内画直线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆