################################################################################### # # Plot 2D maps of samples locations # # Last review: 17/06/2018 # email: ja@fct.unl.pt # ################################################################################### ################################################################################### varcolX <- 1 varcolY <- 2 addpolygon=TRUE titleGRAPH <- "Planta de localização das amostras de solos" ################################################################################### library("ggplot2") library("scales") library("splancs") # http://ggplot2.org/book/ # # Duplicate gtd -> gtdnew # gtdnew <- data.frame(gtd[,c(varcolX,varcolY)]) names(gtdnew)=names(gtd) # # Polygon # hpts <- chull(gtdnew[,1], gtdnew[,2]) hpts <- c(hpts, hpts[1]) X <- cbind(gtdnew[hpts,1],gtdnew[hpts,2]) area <- areapl(X) # # Draw result # if (addpolygon) { ggplot()+ geom_polygon(aes(gtdnew[hpts,1],gtdnew[hpts,2]),colour="black",fill=NA,linetype = 2) + geom_point(data=gtdnew, aes(gtdnew[,1], gtdnew[,2]),shape=22,colour='gray25',size = 2) + ggtitle(paste(titleGRAPH,":",round(area/1,digits=3),"m2")) + labs(x = names(gtdnew)[1], y = names(gtdnew)[2]) + coord_fixed() + theme_bw() } else { ggplot()+ geom_point(data=gtdnew, aes(gtdnew[,1], gtdnew[,2]),shape=10,colour='gray0',size = 3) + ggtitle(titleGRAPH) + labs(x = names(gtdnew)[1], y = names(gtdnew)[2]) + coord_fixed() + theme_bw() }