如何使用更少,更大的箭头使用geom_quiver可视化风数据 [英] How to visualize wind data with geom_quiver using fewer, bigger arrows

查看:345
本文介绍了如何使用更少,更大的箭头使用geom_quiver可视化风数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码覆盖了大湖地区的风速和风向。
1)箭头太多。我如何平均其中的大部分,以便在地图上放置3-5个大箭头?影响他们的颜色?
我不明白这个来自帮助(geom_quiver)

lockquote
vecsize

默认情况下(NULL) ,矢量大小自动确定。如果网格可以被识别,它们将被缩放到网格,否则矢量将不被缩放。通过在此处指定数字输入,可以调整所有箭头的长度。设置vecsize为零将防止缩放箭头。


我相信这些向量被缩放到网格。但是网格是不是均匀分布?




  library(ggmap) 
library(ggquiver)
library(tidyverse)
library(dplyr)
library(scales)
library(rWind)

#风数据
#美国国家气象局(NWS)的全球预报系统(GFS)
#wind.dl(yyyy,mm,dd,tt,lon1,lon2, lat1,lat2,type =读取数据)
#时间:tt选项:00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00(UTC)
wind_data< - wind.dl(2018,3,16,18,-94,-70,41,49)

wind_data_fit< - wind_data% >%
wind.fit()

wind_data< - rename(wind_data,u=ugrd10m(m s-1),v=vgrd10m(m s-1))
df < - mutate(wind_data_fit,u = wind_data $ u,v = wind_data $ v)

median_speed =中位数(df $ speed)


qmplot(lon,lat,data = df,
extent =panel,
geom =blank,
zoom = 6,
maptype =水彩)+
$ b $ scale_colour_gradient2(low =white,mid =black,
high =firebrick,midpoint = median_speed,space =Lab,
na.value = grey50,guide =colourbar)+

geom_quiver(aes(u = u,v = v,color = speed),
center = TRUE,
alpha = 0.7 ,
size = 0.7,#线宽
vecsize = 2)#直线段的长度


解决方案

geom_quiver 为每一行数据绘制一个箭头。减少数字箭头的一个选择是为每一行第n行数据绘制一个箭头。在下面的示例中,我们绘制每隔一行(如此 n = 2 ),将箭头数量减半。唯一必要的变化是在剧情代码的第一行中的 data 参数中:

  qmplot(lon,lat,data = df [seq(1,nrow(df),2),],



比较原始图:





您可以通过选择您想要的任何数据行来进一步减少箭头在这种情况下,请注意,我使用完整的数据框 df 作为的数据参数, qmplot 和过滤后的数据框作为数据参数到 geom_quiver 。这是为了确保地图包含整个经纬度分机即使我们只为几个要点绘制箭头:

 #Latitude to keep 
lat.keep = unique(df $ lat)[seq(2,length(unique(df $ lat)),5)]

qmplot(lon,lat,data = df,
extent =panel,geom =blank,zoom = 6,maptype =水彩画)+
scale_colour_gradient2(低=黄色,mid =黑色,
高= firebrick,midpoint = median_speed,space =Lab,
na.value =grey50,guide =colourbar)+
geom_quiver(data = df%>%
过滤器(%lat.keep%)%>%
group_by(lat)%>%
slice(seq(2,n(),11)),#保留1/11经度
aes(u = u,v = v,color = speed),
center = TRUE,alpha = 1,size = 1,vecsize = 0.9)


The code below overlays wind speed and direction over the Great Lakes. 1) There are too many arrows. How do I average most of them so I can place just 3-5 large arrows on the map?

2) Why are some of the arrows so small, if their speed affects their colour? I don't understand this from help(geom_quiver)

vecsize
By default (NULL), vectors sizing is automatically determined. If a grid can be identified, they will be scaled to the grid, if not, the vectors will not be scaled. By specifying a numeric input here, the length of all arrows can be adjusted. Setting vecsize to zero will prevent scaling the arrows.

I believe these vectors are scaled to the grid. But isn't the grid evenly distributed?


library("ggmap")
library("ggquiver")
library("tidyverse")
library("dplyr")
library("scales")
library(rWind)

# Wind Data
# Global Forecast System (GFS) of the USA's National Weather Service (NWS)
# wind.dl(yyyy, mm, dd, tt, lon1, lon2, lat1, lat2, type = "read-data")
# Time: tt  Options: 00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00 (UTC)
wind_data <- wind.dl(2018, 3, 16, 18,-94, -70, 41, 49)

wind_data_fit <- wind_data %>% 
  wind.fit()

wind_data <- rename(wind_data, "u" = "ugrd10m (m s-1)", "v" = "vgrd10m (m s-1)")
df <- mutate(wind_data_fit, u = wind_data$u, v = wind_data$v)

median_speed = median(df$speed)


qmplot(lon, lat, data = df, 
       extent = "panel", 
       geom = "blank", 
       zoom = 6, 
       maptype = "watercolor") + 

  scale_colour_gradient2(low = "white", mid = "black",
                         high = "firebrick", midpoint = median_speed, space = "Lab",
                         na.value = "grey50", guide = "colourbar") +

  geom_quiver(aes(u = u, v = v, colour = speed),
              center = TRUE,
              alpha = 0.7,
              size = 0.7, # Line width
              vecsize = 2) # Length of straight segment

解决方案

geom_quiver is plotting an arrow for every row of data. One option to reduce the number arrows is to plot an arrow for, say, every nth row of data. In the example below, we plot every other row (so n=2), halving the number of arrows. The only change necessary is in the data argument in the first line of plot code:

qmplot(lon, lat, data = df[seq(1,nrow(df),2), ], 

Compare this with the original plot:

You can reduce the arrows further by selecting whichever rows of data you'd like to plot on the map. See below for an example. In this case, note that I've used the full data frame df as the data argument to qmplot and the filtered data frame as the data argument to geom_quiver. This is to ensure that the map includes the entire lat-lon extent of the full data frame, even though we are plotting arrows for only a few of the points:

# Latitudes to keep
lat.keep = unique(df$lat)[seq(2, length(unique(df$lat)), 5)]

qmplot(lon, lat, data = df,
       extent = "panel", geom="blank", zoom = 6, maptype = "watercolor") + 
  scale_colour_gradient2(low = "yellow", mid = "black",
                         high = "firebrick", midpoint = median_speed, space = "Lab",
                         na.value = "grey50", guide = "colourbar") +
  geom_quiver(data=df %>%
                 filter(lat %in% lat.keep) %>% 
                 group_by(lat) %>%
                 slice(seq(2, n(), 11)), # Keep 1/11th of longitudes
              aes(u = u, v = v, colour = speed),
              center = TRUE, alpha = 1, size = 1, vecsize = 0.9) 

这篇关于如何使用更少,更大的箭头使用geom_quiver可视化风数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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