Reputation: 11
I caculated correlations between temperatures und the date of grape harvest. I stored the results as matrix:
32.5 37.5 42.5 47.5 52.5 57.5 62.5 -12.5 -0.05783118 -0.001655467 -0.07857098 -0.1526494 -0.0007327898 -0.02078552 0.06121682 -7.5 -0.23219824 -0.059952117 -0.06895444 -0.1674386 -0.1311612338 -0.08476390 0.09831010 -2.5 -0.11040995 -0.147325160 -0.15016740 -0.1796807 -0.1819844495 -0.14472899 -0.03550576 2.5 -0.20577359 -0.180857373 -0.15077067 -0.2293366 -0.2577666092 -0.21645676 -0.13044584 7.5 -0.44526971 -0.176224708 -0.15114994 -0.2459971 -0.2741514139 -0.19281484 -0.15683870 12.5 -0.12481683 -0.121675085 -0.16011098 -0.2288839 -0.2503969467 -0.26616721 -0.23089796 17.5 -0.15352693 -0.220012419 -0.11456690 -0.2314059 -0.2194705426 -0.20557053 -0.22529422
Now I want to visualize the results on a map. It should look like this:
example for visualizing correlations on a map
Only my longitude und latitude are different. My latitude ranges from 32,5°N to 62,5°N and my longitude goes from -12,5°E to 17,5°E. I have absolutely no idea how it's been done! It would be nice, if someone can help me. Regards.
Upvotes: 1
Views: 734
Reputation: 228
The corrplot() function from corrplot R package can be used to plot a correlogram.
library(corrplot)
M<-cor(mtcars) # compute correlation matrix
corrplot(M, method="circle")
this is described here:
Online R software is also available to compute and visualize a correlation matrix, by a simple click without any installation :
http://www.sthda.com/english/rsthda/correlation-matrix.php
Upvotes: 0
Reputation: 59345
This is one way. Your grid is rather coarse (increments of 5°, or ~350 miles at the equator), and of course you did not provide an actual map, but this will plot a "heat map" of correlation at the coordinates you provided.
df <- cbind(lon=rownames(df),df)
library(reshape2)
library(ggplot2)
library(RColorBrewer)
gg <- melt(df,id="lon",variable.name="lat",value.name="corr")
gg$lat <- as.numeric(substring(gg$lat,2)) # remove pre-pended "X"
gg$lon <- as.numeric(as.character(gg$lon)) # convert factor to numeric
ggplot(gg)+
geom_tile(aes(x=lon,y=lat, fill=corr))+
scale_fill_gradientn(colours=rev(brewer.pal(9,"Spectral")))+
coord_fixed()
Upvotes: 1