Adding points to a plot properly

Hi all,

I am attempting to add points to a plot properly but cant seem to solve it. Here is as it follows:

My set of data from 1976 for discharge:

q1976
[1] 0.12 0.53 0.49 0.40 0.30 0.43 0.46 0.38 0.27 0.23 0.20 0.22 0.21 0.21 0.26 0.46 0.74 0.68 0.44 0.41 0.57 0.66 0.87 0.61
##Shortening it so it doesnt fill too much##
[361] 0.18 0.17 0.14 0.13 0.13 0.14

This is what I plot with type="l" for the line type. What I am trying to accomplish is have points at events greater than or equal to the 95th percentile (which is equal to 0.77 and greater:
points(q1976[q1976 >= 0.77], pch="*", col="2")

What I end up getting however, are points all shoved to the left of the plot and not even on the line of the plot.

I'm not sure if you can see the uploaded picture but it shows what I end up getting. I'm trying to have the points on the actual events that are at or above 0.77 in value.

Thanks in advance for the help!

It seems you are plotting the line graph without explicit x values; just using the position in the sequence to set x. If so, you can use the which() function to find out where the y values greater than the 95th percentile occur.

set.seed(1)
DF <- data.frame(Discharge = runif(300, min = 0, max = 10))
Q95 <- quantile(DF$Discharge, probs = 0.95)
Q95
#>      95% 
#> 9.346921
plot(DF$Discharge, type = "l")
points(which(DF$Discharge >= Q95), DF[DF$Discharge >= Q95, "Discharge"])

Created on 2020-03-09 by the reprex package (v0.3.0)

Thank you so much for the help. I am new to R so I do not fully understand all you've done but I have been able to get the points correctly on my graph. I will look into it more soon.

Thanks again!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.