我正在分析qPCR数据,并且我有一个Y值阈值,我想要获得相应的X值。这是我的绘图代码:
library(ggplot2)
ggplot() +
geom_line(data=qPCR_amplification_plot_data_IFI6, aes(x=`Cycle`, y=`dRn...3`))+
geom_line(data=qPCR_amplification_plot_data_IFI6, aes(x=`Cycle`, y=`dRn...5`))+
geom_point()+
labs(y = "ΔRn", title = "Amplification plot", x= "Cycle")+
scale_y_continuous(trans='log10', limits = c(0.001,10))+
geom_hline(yintercept = 0.04)我知道如何获得某个X值的Y值:
Intersect <- approxfun(qPCR_amplification_plot_data_IFI6$Cycle, qPCR_amplification_plot_data_IFI6$dRn...3)
Intersect(X)但是我想得到Y阈值的X值(例如0.4)。我该怎么做呢?
发布于 2020-04-16 21:26:04
您可能可以使用which()和near() (来自dplyr)的组合来完成此操作。which()可以有效地评估“这部分是真的”:
x <- 1:100
> which(x==4)
[1] 4near()可以用作“某种接近”的逻辑表达式--非常适合于近似:
4 == 4.01
[1] FALSE
near(4, 4.01, tol=0.01)
[1] TRUE
near(4, 4.01, tol=0.001)
[1] FALSE因此,您可以将这两者结合起来,基本上回答这个问题:“在我的向量Intersect中,哪个X值与Y接近?”
which(near(Intersect, Y, tol = your.tolerance))顺便说一句,我假设代码中的Intersect(X)是一个拼写错误,并且您有一个向量Intersect[X]
https://stackoverflow.com/questions/61246943
复制相似问题