First, you should load recharts
:
library(recharts)
Heatmap has 1 basic type: heatmap.
The keys are:
x
y
, numeric lat
and lng
echartr(data, y, lng, lat, <series>, <t>, <type>)
Arg | Requirement |
---|---|
data |
source data in the form of data.frame |
y |
numeric dependent variable. Only the first one is accepted. |
series |
series variable which will be coerced to factors. Only the first one is accepted if multiple variables are provided. |
lng |
longitude or x-coordinate. |
lat |
latitude or y-coordinate. |
t |
timeline variable which will be coerced to factors. Only the first one is accepted if multiple variables are provided. |
type |
‘heatmap’ |
Here is a fictious dataset.
data = rbind(
data.frame(
lng=100+rnorm(100,0, 1)*600, lat=150+rnorm(100,0, 1)*50,
y=abs(rnorm(100,0,1))),
data.frame(
lng=rnorm(200,0, 1)*1000, lat=rnorm(200,0, 1)*800,
y=abs(rnorm(200,0,1))),
data.frame(lng=400+rnorm(20,0, 1)*300, lat=5+rnorm(20,0, 1)*10,
y=abs(rnorm(100,0,1))))
str(data)
## 'data.frame': 400 obs. of 3 variables:
## $ lng: num 539.4 43.9 668.4 -192.1 -90.3 ...
## $ lat: num 166 162 273 203 121 ...
## $ y : num 0.591 0.801 0.908 0.498 1.195 ...
echartr(data,lng=lng,lat=lat,y=y,type='heatmap') %>%
setTitle("Heatmap", "Fictious Data")
Heatmap is more useful in maps. You can refer to addHeatmap
for help.
Then you can configure the widgets, add markLines and/or markPoints, fortify the chart.
You can refer to related functions to play around on your own.