将传单地图另存为html文件

时间:2018-05-24 02:37:53

标签: html r leaflet maps

我使用USDA NASS数据创建了堪萨斯州玉米产量的传单图。我遇到的问题是使用以下命令将传单导出到html文件中:

htmlwidgets::saveWidget(my_interactive_map, "kansas_corn2.html")

但是我收到了这个错误:

Error in system.file(config, package = package) : 'package' must be of length 1

但是,我可以使用Export>生成一个html文件。从“查看器”窗格中另存为“网页..”。

html leaflet export

如何使用命令行实现相同的导出结果? 我制作地图的代码是:

my_interactive_map <- tm_shape(STATE) +
tm_polygons("Value", textNA = "Not Reported", 
          title = unit_desc, palette=c('#8290af','#512888','#190019'),
          auto.palette.mapping=FALSE, n = 6, style = "quantile", contrast = 0.9, colorNA = "#C0C0C0",
          border.col = "#E8E8E8", showNA = FALSE, legend.is.portrait = FALSE,
          legend.hist = FALSE, popup.vars = c("County: " = "COUNTY_NAME", "Value: " = "Value")) +
 tm_credits("U.S. Department of Agriculture, National Agriculture Statistics Service") +
 tm_format_World(title = paste(year_filt, prodn_practice_desc, commodity_desc, statisticcat_desc, "by", 
                            agg_level_desc, "for", state, sep = " "))
my_interactive_map

1 个答案:

答案 0 :(得分:0)

您似乎正在使用tmap库。为此,您可以使用详细功能 here

library(tmap) 
save_tmap(my_interactive_map, "kansas_corn2.html")