Saturday 15 March 2014

r - Overlay map using ggplot2 -



r - Overlay map using ggplot2 -

i using ggplot2 plot matrix, , using geom_text add together letters in each point. now, wondering if possible , how, overlaying map, since values represent european region. try:

library(ggplot2) mat1<- melt(vals[,t.lat]) # matrix [long,lati] mat2<- melt(names[,t.lat]) # matrix [long,lati] p <-ggplot(mat1, aes(lon,lat, fill=val)) + geom_raster() + geom_text(label = mat2$val,na.rm=true,size=3)+ scale_fill_gradient(low = "white", high = "red",na.value="white")

the image code is:

i know if possible ggplot2 adding contour map define regions . thought that???

thanks in advance comments. seek create reproducible sample (since original info much). construction same, except original matrix have na.

library(ggplot2) #coordinates lati <- seq(from = 72, = 34, =-1) loni <- seq(from=-13,to=34,by=1) m1 <- array(runif(length(loni)*length(lati)),dim=c(length(loni),length(lati))) m2 <- array(c("a","b"),dim=c(length(loni),length(lati))) t.lat <-c(length(lati):1) #reverse latitude mat1<- melt(m1[,t.lat]) # matrix [long,lati] mat2<- melt(m2[,t.lat]) names(mat1) <- c("lon","lat","val") names(mat2) <- c("lon","lat","val") p <-ggplot(mat1, aes(lon,lat, fill=val)) + geom_raster() + geom_text(label = mat2$val,na.rm=true,size=3)+ scale_fill_gradient(low = "white", high = "red",na.value="white")

then, overlay area defined coordinates , loni , lati, similar add together map in background. hope question clearer example.

thanks again.

r

No comments:

Post a Comment