简体   繁体   English

使用传单生成总计数图

[英]Using leaflet to produce plot with total count

I am trying to use the leaflet package in R to produce an interactive visual which helps me visualize the following data:我正在尝试使用 R 中的传单包来生成交互式视觉效果,这有助于我可视化以下数据:

      Provice      Lat     Long     Date Confirmed Recovered Deaths
1       Anhui 31.82570 117.2264 20-01-22         1         0      0
2       Anhui 31.82570 117.2264 20-01-23         9         0      0
3       Anhui 31.82570 117.2264 20-01-24        15         0      0
4       Anhui 31.82570 117.2264 20-01-25        39         0      0
5       Anhui 31.82570 117.2264 20-01-26        60         0      0
6       Anhui 31.82570 117.2264 20-01-27        70         0      0
7       Anhui 31.82570 117.2264 20-01-28       106         0      0
8       Anhui 31.82570 117.2264 20-01-29       152         2      0
9       Anhui 31.82570 117.2264 20-01-30       200         2      0
10      Anhui 31.82570 117.2264 20-01-31       237         3      0

Note: There are 10 Provices in total each with their respective coordinates.注:共有 10 个省份,每个省份都有各自的坐标。

So far I have been able to create the following image:到目前为止,我已经能够创建以下图像: 在此处输入图片说明

using the following code:使用以下代码:


dta2 %>% 
  leaflet() %>%
  addProviderTiles(providers$OpenStreetMap) %>%
  addMarkers(label = dta2$Confirmed  , lng = dta2$Long, lat = dta2$Lat ,clusterOptions = markerClusterOptions(), popup = ~paste("Provice:", dta2$Provice))

However, my goal is to display the total number of confirmed cases for this virus at each cluster as opposed to the number of observations for each cluster (there are 22 obs for each province).但是,我的目标是显示每个集群中该病毒的确诊病例总数,而不是每个集群的观察数(每个省有 22 个观察)。 In other words, I would like to display the sum of the confirmed column for each of the 10 provinces in their individual clusters as opposed to a frequency.换句话说,我想显示单个集群中 10 个省中每个省的确认列的总和,而不是频率。 Can anybody please shed some light on this for me?有人可以帮我解释一下吗?

It's difficult to be sure my proposition works fine since I don't have access to your data.由于我无法访问您的数据,因此很难确定我的提议是否有效。 But I think the following might work.但我认为以下可能有效。 Please note that I'm using the data.table package to summarize the data, you will need to install it if you don't already have it.请注意,我正在使用data.table包来汇总数据,如果您还没有安装它,则需要安装它。

library(data.table)

# Summarize the data
setDT(dta2)
dta2 <- dta2[, .(
  Confirmed = sum(Confirmed),
  Recovered = sum(Recovered),
  Deaths = sum(Deaths)
), .(Provice, Lat, Long)]

# Create the leaflet map
leaflet(dta2) %>%
  addProviderTiles(providers$OpenStreetMap) %>%
  addLabelOnlyMarkers(
    lng = ~Long,
    lat = ~Lat,
    label = ~Confirmed,
    labelOptions = labelOptions(noHide = TRUE)
  )

You can customize the display with the argument labelOptions of the addLabelOnlyMarkers() function if you want.如果需要,您可以使用addLabelOnlyMarkers()函数的参数labelOptions自定义显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM