Reputation: 11
corval<-cor(airquality$Solar.R,airquality$Temp,use="complete.obs")
coord<-locator(n=1)
text(coord,expression("Correlation=", corval))
I'm trying to add text that contains both a string and an integer to a plot but I can't find out how to get the numerical value of the variable to display, this is just one of the ways I've tried.
Upvotes: 1
Views: 5282
Reputation: 37641
I think that you mean to plot airquality$Solar.R against airquality$Temp and then add this label to the plot. If you have clicked on a good place for the center of the text, you can use:
plot(airquality$Solar.R,airquality$Temp)
text(coord, paste0("Corval=", round(corval, 3)))
Upvotes: 1