# Tue Aug 25 21:40:43 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2 for window 10
# cgh163email@163.com
# —— 拎了个梨🍐
# 迁徙图
require(mapdeck)
key <- 'pk.eyJ1IjoieW*************fUg'
set_token( key )
# url <- 'https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv'
flights <- read.csv('2011_february_aa_flight_paths.csv')
flights$id <- seq_len(nrow(flights))
flights$stroke <- sample(1:3, size = nrow(flights), replace = T)
flights$info <- paste0("<b>",flights$airport1, " - ", flights$airport2, "</b>")
head(flights)
# start_lat start_lon end_lat end_lon airline airport1 airport2 cnt id stroke info
# 1 33.94254 -118.4081 21.97598 -159.3390 AA LAX LIH 56 1 3 <b>LAX - LIH</b>
# 2 32.89595 -97.0372 21.31869 -157.9224 AA DFW HNL 112 2 1 <b>DFW - HNL</b>
mapdeck(token = key,
style = mapdeck_style('light'),
pitch = 35) %>% # 底图
add_animated_arc(data = flights, # 数据框
origin = c('start_lon','start_lat'), # 开始坐标
destination = c('end_lon','end_lat')) # 终点坐标
后面的官方实例无法运行,不知道为什么。2020年8月25日
Wed Aug 26 00:10:07 2020 --多参数实例----------------------------
# Tue Aug 25 21:47:56 2020 --官方实例运行不了
# animation_arc是实验层,该函数可能会更改而不会发出警告
# 2020年8月26日能用的参数。
# 凡是颜色的参数都用不了,可能是我没看懂。
mapdeck(token = key,
style = mapdeck_style('light'),
pitch = 35) %>% # 底图前后视觉倾斜度
add_animated_arc(data = flights, # 数据框
origin = c('start_lon','start_lat'), # 开始坐标
destination = c('end_lon','end_lat'), # 终点坐标
layer_id = 'id',
id = 'id',
stroke_width = 'airport2',
animation_speed = 50, # 速度
trail_length = 10, # 弧线长度
tilt = 50, # 弧线倾斜弧度
height = 15, # 弧线高度 值
tooltip = 'info', # 鼠标提示文字
auto_highlight = T, # 鼠标高亮
focus_layer = T, # 边界更新
transitions = 5, # 持续时间
brush_radius = T)# 鼠标热点不显示
# Wed Aug 26 00:09:46 2020 ---End---------------------------
参数列表:
text 版:
Add animated arc 添加动画弧 迁徙图
map a mapdeck map object
data data to be used in the layer. All coordinates are expected to be EPSG:4326 (WGS 84) coordinate system 图层中要使用的数据。 所有坐标均应为EPSG:4326(WGS 84)坐标系
layer_id single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly 指定图层ID的单个值。 使用此值可以区分相同类型的形状图层。 具有相同ID的图层可能会发生冲突并且无法正确绘制
origin vector of longitude and latitude columns, and optionally an elevation column, or an sfc column 经度和纬度列的向量,还可以选择是海拔列或sfc列
destination vector of longitude and latitude columns, and optionally an elevatino column, or an sfc column 经度和纬度列的向量,以及elevatino列或sfc列(可选)
id an id value in data to identify layers when interacting in Shiny apps. 数据中的ID值,以在“闪亮”应用程序中进行交互时识别图层。
stroke_from column of data or hex colour to use as the staring stroke colour. IIf using a hex colour, use either a single value, or a column of hex colours on data 数据列或十六进制颜色,用作凝视笔触颜色。 IIf使用十六进制颜色,在数据上使用单个值或一列十六进制颜色
stroke_from_opacity Either a string specifying the column of data containing the stroke opacity of each shape, or a value between 1 and 255 to be applied to all the shapes. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string 指定包含每个形状的笔触不透明度的数据列的字符串,或要应用于所有形状的1到255之间的值。 如果使用十六进制字符串作为颜色,则将忽略此参数,并且应在十六进制字符串中包含alpha
stroke_to column of data or hex colour to use as the ending stroke colour. If using a hex colour, use either a single value, or a column of hex colours on data 数据列或十六进制颜色,用作结束笔触颜色。 如果使用十六进制颜色,请在数据上使用单个值或一列十六进制颜色
stroke_to_opacity Either a string specifying the column of data containing the stroke opacity of each shape, or a value between 1 and 255 to be applied to all the shapes. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string 指定包含每个形状的笔触不透明度的数据列的字符串,或要应用于所有形状的1到255之间的值。 如果使用十六进制字符串作为颜色,则将忽略此参数,并且应在十六进制字符串中包含alpha
stroke_width width of the stroke in pixels 笔划的宽度(以像素为单位)
frequency column of data, or a single value indicating the number of arcs generated in each animation 数据列,或一个值,指示每个动画中生成的弧数
animation_speed the speed of animation 动画速度
trail_length the length of trail of each arc 每条弧线的长度
tilt value to tilt the arcs to the side, in degrees [-90, 90] 弧度向侧面倾斜的值,以度为单位[-90,90]
height value to multiply the height. 乘以高度的值。
tooltip variable of data containing text or HTML to render as a tooltip 包含文本或HTML的数据变量以呈现为工具提示
auto_highlight logical indicating if the shape under the mouse should auto-highlight 逻辑指示鼠标下方的形状是否应自动突出显示
highlight_colour hex string colour to use for highlighting. Must contain the alpha component. 用于突出显示的十六进制字符串颜色。 必须包含alpha分量。
legend either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend. 逻辑指示是否应显示图例,或者是一个命名列表,该列表指示应在图例中包括哪些颜色属性。
legend_options A list of options for controlling the legend. 用于控制图例的选项列表。
legend_format A list containing functions to apply to legend values. See section legend 包含要应用于图例值的函数的列表。 参见图例
palette "string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")" “字符串或矩阵。字符串将是colourvalues :: colour_palettes()之一。矩阵必须至少包含5行,且[0,255]之间的值包含3或4列,其中第4列表示Alpha。您可以 使用命名列表为不同的颜色选项(如果有)指定不同的调色板,例如list(fill_colour =“ viridis”,stroke_colour =“ inferno”)“
na_colour hex string colour to use for NA values 用于NA值的十六进制字符串颜色
update_view logical indicating if the map should update the bounds to include this layer 逻辑指示地图是否应更新边界以包括此图层
focus_layer logical indicating if the map should update the bounds to only include this layer 逻辑指示地图是否应将边界更新为仅包括此图层
transitions list specifying the duration of transitions. 指定过渡持续时间的列表。
digits number of digits for rounding coordinates 舍入坐标的位数
brush_radius radius of the brush in metres. Default NULL. If supplied, the arcs will only show if the origin or destination are within the radius of the mouse. If NULL, all arcs are displayed 画笔的半径(以米为单位)。 默认为NULL。 如果提供了弧,则仅当起点或终点在鼠标的半径内时才会显示弧。 如果为NULL,则显示所有弧