Reputation: 706
I am trying to create a plot with heatmap using plotly add_heatmap() function, but it generates an error message saying Error: Must supply z
attribute I referred to this site for addHeatmap() function provided by leaflet.extras package.
The following code only displays dots from addCircles() and outputs a warning message and a map as shown below:
final_df %>%
leaflet() %>%
addTiles() %>%
addCircles(
lng = final_df$long,
lat = final_df$lat,
popup = final_df$station_name
) %>% addHeatmap(lng = final_df$long, lat = final_df$lat, radius=5)
I have tried a different function add_heatmap() from leaflet which does not display any maps and generates an error.
final_df %>%
leaflet() %>%
addTiles() %>%
addCircles(
lng = final_df$long,
lat = final_df$lat,
popup = final_df$station_name
) %>% add_heatmap(lng = final_df$long, lat = final_df$lat)
Anyone faced a similar issue and created a heatmap on R?
Upvotes: 0
Views: 3494
Reputation: 411
Remove addCircles part and try:
library(leaflet.extras)
final_df %>%
leaflet() %>%
addTiles() %>%
addHeatmap(lng = final_df$long, lat = final_df$lat, blur = 40, max = 0.05, radius = 15)
Upvotes: 4