如何用R绘制风向和速度(速度图)

Wav*_*ave 2 r

基本上我有2个矩阵(u和v)的列表,包含纵向和横向的风速(以及包含坐标的向量x和y).我想制作一个带有箭头指向最终方向的地图,其大小与风速成正比.之前提出过这个问题:http: //www.mail-archive.com/r-help@r-project.org/msg18875.html.不幸的是,答案中给出的链接被打破了.我尝试使用箭袋功能,但我没有让它工作.

以下是我的数据的样子:

x=seq(10,15,by=0.25)
y=seq(40,50,by=0.25)
u=matrix(runif(length(x)*length(y),-2,3),nrow=length(y),ncol=length(y))
v=matrix(runif(length(x)*length(y),-2,3),nrow=length(y),ncol=length(y))
wind=list(u,v)
Run Code Online (Sandbox Code Playgroud)

对于箭袋功能:

library(pracma)
quiver(x=x, y=y, u=wind[[1]], v=wind[[2]])
Run Code Online (Sandbox Code Playgroud)

哪两次给出:

Error: invalid graphics state
Run Code Online (Sandbox Code Playgroud)

我假设你和v是错误的并且也需要坐标,但老实说我不理解包描述中给出的解释(u,v:x,起点的y坐标).

我在matlab或python中看到更多信息可用于箭袋,但我从未使用过,所以任何有关在R中执行此操作的建议都将非常感激.

Rol*_*and 7

x=seq(10,15,by=0.25)
y=seq(40,50,by=0.25)
u=matrix(runif(length(x)*length(y),-2,3),nrow=length(x),ncol=length(y))
v=matrix(runif(length(x)*length(y),-2,3),nrow=length(x),ncol=length(y))
#note that I corrected these

#melt for plotting
library(reshape2)
u <- melt(u,value.name = "u")
v <- melt(v,value.name = "v")
wind <- merge(u, v)
wind$x <- x[wind[,1]]
wind$y <- y[wind[,2]]


#plot
library(ggplot2)
library(grid)
scaler <- 1

p <- ggplot(wind, aes(x=x, y=y, xend=x+u*scaler, yend=y+v*scaler)) + geom_segment(arrow=arrow())
print(p)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述