6

I am very new in programming and I want to ask how can I make a scatterplot of two rasters in R and also get their correlation?

1
  • I suspect you mean "coefficient of determination"?
    – Spacedman
    Oct 17, 2014 at 8:05

1 Answer 1

9

If the rasters have the same basis (extent, resolution etc) then you just get the values and plot them. Something like:

 plot(values(r1), values(r2))

I'm not sure exactly what the "correlation of determination" is, but the simple "correlation" can be computed by:

 cor(values(r1), values(r2))

Note these are both dependent on the rasters having identical grid structures.

3
  • 1
    You don't need to use values(). plot(r1, r2) will work. Oct 17, 2014 at 8:28
  • 1
    I'm never sure when raw rasters work and when you need values() so I played it cautious without testing!
    – Spacedman
    Oct 17, 2014 at 8:51
  • 1
    Just for completeness. The coefficient of determination (R²) is the square of coefficient of correlation (r). Feb 7, 2019 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.