我希望在传单中创建英国的选区地图,将鼠标悬停在其上时会提供选区名称和详细结果。
数据包含在具有 2 列的tibble中:
- 选区,其中包含名称
- 结果,它是每个单元格内的列表列,其中包含一个数据框,包括候选人姓名、政党、投票、%和订单。
我在下面包含了两个选区的样本
df <- structure(list(constituency = c("Knowsley", "Bristol West"),
result = list(structure(list(name = c("George Howarth", "James Spencer",
"Neil Miney", "Carl Cashman", "Steve Baines"), party = c("Labour",
"Conservative", "UKIP", "LD", "Green"), votes = c(47351L,
5137L, 1285L, 1189L, 521L), pc = c(85.34, 9.26, 2.32, 2.14,
0.94), order = 1:5), .Names = c("name", "party", "votes",
"pc", "order"), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")), structure(list(name = c("Thangam Debbonaire",
"Annabel Tall", "Molly Scott Cato", "Stephen Williams", "Jodian Rodgers"
), party = c("Labour", "Conservative", "Green", "LD", "Money Free Party"
), votes = c(47213L, 9877L, 9216L, 5201L, 101L), pc = c(65.93,
13.79, 12.87, 7.26, 0.14), order = 1:5), .Names = c("name",
"party", "votes", "pc", "order"), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame")))), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"), .Names = c("constituency", "result"))
如果我只想要标签中的选区,我会这样编码,我可以将其应用于传单输出:
labels <- sprintf(
df$constituency
) %>% lapply(htmltools::HTML)
但我希望添加结果详细信息。