Potato
Potato

Reputation: 172

Problem with understanding usage of identify

i need to paint a graph using LakeHuron data in R, single paiting is easy just

df= data.frame(LakeHuron)
plot(df)

but I need to use identify to sign the years where the point of water was the highest and the lowest

df=data.frame(LakeHuron)
df
plot(df)
minimum = min(df)
maximum = max(df)

I got those minimum and maximum variables, but how can i use identify to point them on plot?

Upvotes: 0

Views: 46

Answers (2)

G5W
G5W

Reputation: 37661

If you are trying to label the years, it may be easiest to do that with text.

Xmin = which.min(df$LakeHuron)
Xmax = which.max(df$LakeHuron)
Years = 1875:1972

plot(df)
text(x=Years[c(Xmin, Xmax)], y = LakeHuron[c(Xmin, Xmax)], 
    labels=Years[c(Xmin, Xmax)], pos=4)

First chart

If you really want to use identify, you can use

plot(df)
Years = 1875:1972
identify(x=Years, y=LakeHuron, labels=Years)

Then click near the maximum and minimum. Right click and select "stop" when you are done.

Upvotes: 1

Gilgamesh
Gilgamesh

Reputation: 629

Try adding this piece of code

minx <- which(df$LakeHuron == minimum)
maxx <- which(df$LakeHuron == maximum)
points(x = 1874 + minx,minimum, col = "red")
points(x = 1874 + maxx,maximum, col = "red")

I've used the points function to plot points on your graph. You could change its visual. To that, see the page website

Upvotes: 2

Related Questions