Question: Maximum values in plot
1
gravatar for Grunir112
2.1 years ago by
Grunir11210
Grunir11210 wrote:

I have a plot,where y-axis are obervations and x-axis is time. I have to find the maximun (x,y point) from the plot. I used max(), but I only figured out the obervation value but not the time point where this max obervation value is. Could someone help me please?

R • 660 views
ADD COMMENTlink modified 2.1 years ago by zx87546.5k • written 2.1 years ago by Grunir11210
4

And how is the data structured? You can probably find this easier in your original dataframe/matrix than in a plot.

ADD REPLYlink written 2.1 years ago by WouterDeCoster36k
1

Take a look at ?which.max and maybe ?max.col functions in R.

ADD REPLYlink written 2.1 years ago by ddiez1.7k
6
gravatar for zx8754
2.1 years ago by
zx87546.5k
London
zx87546.5k wrote:

Try this example, using base plot:

# dummy data
df1 <- mtcars[1:10, 1:2]

# plot
plot(df1$mpg, df1$cyl)

# get the max on y, and matching x value
df1Max <- df1[ which(max(df1$cyl) == df1$cyl), ]

# mark the max point on the plot
points(df1Max$mpg, df1Max$cyl, col = "red", pch = 19)

# add vertical line
abline(v = df1Max$mpg, col = "blue", lty = "dashed")

enter image description here

ADD COMMENTlink modified 7 months ago • written 2.1 years ago by zx87546.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2152 users visited in the last hour