leaflet.minicharts (version 0.6.2)

addFlows: Add or modify flows on a leaflet map

Description

These functions can be used to represent flows and their evolution on a map created with leaflet(). Flows are simply represented by a segment between two points with an arrow at its center that indicates the direction of the flow.

Usage

addFlows(
  map,
  lng0,
  lat0,
  lng1,
  lat1,
  color = "blue",
  flow = 1,
  opacity = 1,
  dir = NULL,
  time = NULL,
  popup = popupArgs(labels = "Flow"),
  layerId = NULL,
  timeFormat = NULL,
  initialTime = NULL,
  maxFlow = max(abs(flow)),
  minThickness = 1,
  maxThickness = 20,
  popupOptions = NULL
)

updateFlows( map, layerId, color = NULL, flow = NULL, opacity = NULL, dir = NULL, time = NULL, popup = NULL, timeFormat = NULL, initialTime = NULL, maxFlow = NULL, minThickness = 1, maxThickness = 20, popupOptions = NULL )

removeFlows(map, layerId)

clearFlows(map)

Arguments

map

A leaflet map object created with leaflet.

lng0

Longitude of the origin of the flow.

lat0

Latitude of the origin of the flow.

lng1

Longitude of the destination of the flow.

lat1

Latitude of the destination of the flow.

color

Color of the flow.

flow

Value of the flow between the origin and the destination. If argument dir is not set, negative values are interpreted as flows from destination to origin.

opacity

Opacity of the flow.

dir

Direction of the flow. 1 indicates that the flow goes from origin to destination and -1 indicates that it goes from destination to origin. If 0, the arrow is not drawn. If NULL, then it is equal to the sign of weight.

time

A vector with length equal to the number of rows in chartdata and containing either numbers representing time indices or dates or datetimes. Each unique value must appear as many times as the others. This parameter can be used when one wants to represent the evolution of some variables on a map.

popup

Options that control popup generation.

layerId

An ID variable. It is mandatory when one wants to update some chart with updateMinicharts.

timeFormat

Character string used to format dates and times when argument time is a Date, POSIXct or POSIXlt object. See strptime for more information.

initialTime

This argument can be used to set the initial time step shown when the map is created. It is used only when argument time is set.

maxFlow

Maximal value a flow could take.

minThickness

minimal thickness of the line that represents the flow.

maxThickness

maximal thickness of the line that represents the flow.

popupOptions

Change default popupOptions (ex : autoClose, maxHeight, closeButton ...) See popupOptions for more informations.

Value

The modified leaflet map object.

Examples

Run this code
# NOT RUN {
require(leaflet)

# Toy example
leaflet() %>% addTiles() %>%
  addFlows(0, 0, 1, 1, flow = 10)

# Electric exchanges between France and neighboring countries
data("eco2mixBalance")
bal <- eco2mixBalance
leaflet() %>% addTiles() %>%
  addFlows(
    bal$lng0, bal$lat0, bal$lng1, bal$lat1,
    flow = bal$balance,
    time = bal$month
  )

# popupOptions
data("eco2mixBalance")
bal <- eco2mixBalance
leaflet() %>% addTiles() %>%
  addFlows(
    bal$lng0, bal$lat0, bal$lng1, bal$lat1,
    flow = bal$balance,
    time = bal$month,
    popupOptions = list(closeOnClick = FALSE, autoClose = FALSE)
  )

# }

Run the code above in your browser using DataCamp Workspace