我如何绘制R中的地理参考数据集? [英] How can I plot a georeferenced dataset in R?

查看:195
本文介绍了我如何绘制R中的地理参考数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网格数据,我想在美国地图上绘制:



紧跟在行之后:

  all_data = read.table(windspeed.txt,header = TRUE)

使用以下命令反转行号:

pre $ max_row = max(all_data $ row)
all_data $ row = max_row-all_data $ row

这应该照顾它。


I have this gridded data that I want to plot on a US map: https://www.dropbox.com/s/9khcjgtv8ipo2u5/windspeed.txt?dl=0

library(ggplot2)
library(RColorBrewer)
library(rgdal)
library(sp)
library(maps)
options(max.print=5.5E5) 

all_data = read.table("windspeed.txt",header = TRUE)

res=0.01 #spacing of row and col coords pre-specified
origin_lat_lon=c(24.55, -130) 
all_data$row=(all_data$row)*res+origin_lat_lon[1] 
all_data$col=(all_data$col)*res+origin_lat_lon[2]
coords = cbind(all_data$col, all_data$row)
spdf = SpatialPointsDataFrame(coords, data=all_data) #sp = SpatialPoints(coords)
proj4string(spdf) <- CRS("+init=epsg:4269") 

df=as.data.frame(spdf)
myPalette <- colorRampPalette(rev(brewer.pal(10, "Spectral")))
usamap <- map_data("state")
ggplot(data=df,aes(x=col,y=row,color=m)) + 
  geom_polygon( data=usamap, aes(x=long, y=lat,group=group),colour="black", fill="white" )+
  geom_point()+
  scale_colour_gradientn(name = "Wind",colours = myPalette(10), limits=c(0,1))+
  xlab('Longitude')+
  ylab('Latitude')+
  theme_bw()+
  theme(line = element_blank())+
  theme(legend.position = c(.93,.20),panel.grid.major = element_line(colour = "#854440"))+
  ggsave("test.png",width=10, height=8,dpi=300)

But I am getting an inverted plot. Can you please help?

I previously got an answer for a similar dataset here: How to convert point data collected at grid interval to a georeferenced dataset in r?

解决方案

Your latitude values in this csv are reverted when compared to the dataset you previously had from the previous question you mentioned. All you have to do is to invert the row numbers in this new dataset:

Right after your line:

all_data = read.table("windspeed.txt",header = TRUE)

Invert the row numbers using:

max_row= max(all_data$row)
all_data$row=max_row-all_data$row 

That should take care of it.

这篇关于我如何绘制R中的地理参考数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆