Identifying points in a curve

僤鯓⒐⒋嵵緔 提交于 2019-12-12 08:45:49

问题


I feel like this is an easy question...

How do you identify coordinates in a figure? I plotted some data, used unireg (the uniReg package) to make a spline curve, and want to pull out the data from a point.

library(uniReg)
P0mM <- read.table(text="
Time           FeuM
0.04    138.8181818
   7    1258.636364
  14    1320.545455
  21     2110.37037
  28    13730.37037
  35    1550.909091",header=TRUE)

z=seq(min(P0mM$Time),max(P0mM$Time),length=201)
uf=with(P0mM,unireg(Time,FeuM,g=5,sigma=1))
plot(FeuM~Time,P0mM,ylim=c(0,16000),ylab="Fe2+ uM", xlab="Time", main="0mM P")
lines(z,uf$unimod.func(z))

I was able to find the max y value of the curve (which is 14444)

max((uf$unimod.func(z)))

I want to identify where on the x axis this happens. (Should be around 30, but I want to be exact).

How do you do this?

Thanks!


回答1:


Seems like a case for optimise or optimize (depending on your affinity with British or American English):

optimise(uf$unimod.func, maximum=TRUE, interval=range(P0mM$Time))
#$maximum
#[1] 29.27168
#
#$objective
#         [,1]
#[1,] 14444.85


来源:https://stackoverflow.com/questions/31106237/identifying-points-in-a-curve

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!