微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

tmap_arrange 上的 tmap_animation

如何解决tmap_arrange 上的 tmap_animation

我有一个包含 tmap_arrange 对象的列表,其中包含 156 个我希望为它们设置动画的列表。我已经为单个 tmap 绘图完成了这项工作,但现在我希望将这三个图合并为一个页面

看来 tmap_animate 无法处理 tmap_arrange 对象。列表的每个元素看起来像这样

Three plots arranged through tmap

生成这些图的代码如下。

hazard_map <- lapply(list_tend,function(x) tmap_arrange(
  tm_shape(x,bBox = bounding_Box) +
    tm_polygons(col = "ci_lower",palette = "viridis",style = "fixed",breaks = c(0,min(hazard_farmed$ci_lower,na.rm = T),0.000000001,0.00000001,0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1,10,100,1000,max(hazard_farmed$ci_upper,na.rm = T)),lwd = 0.1,title = "Lower C.I.",legend.format = list(scientific = TRUE)) +
    tm_shape(neighbour_map) +
    tm_polygons(alpha = 0.2) +
    tm_text("adm0_a3",size = 0.3) +
    if(!nrow(observed_cases %>% 
             filter(month_case %in% x$tend)) < 1) { tm_shape(observed_cases %>%
                                                               filter(month_case %in% x$tend)) +
        tm_dots() +
        tm_layout(main.title = paste("Lower C.I. of an ASF case in month ",unique(x$tend)),legend.outside = T) +
        tm_credits(text = "Black dots are observed outbreaks",position=c("left","bottom"))}
  else {tm_layout(main.title = paste("Lower C.I. of an ASF case in month ",legend.outside = T) +
      tm_credits(text = "Black dots are observed outbreaks","bottom")) },tm_shape(x,bBox = bounding_Box) +
    tm_polygons(col = "hazard",title = "Hazard",size = 0.3) +
    if(!nrow(observed_cases %>% 
             filter(month_case %in% x$tend)) < 1) { tm_shape(observed_cases %>%
                                                               filter(month_case %in% x$tend)) +
        tm_dots() +
        tm_layout(main.title = paste("Hazard of an ASF case in month ",legend.outside = T) +
        tm_compass(type = "arrow",size = 2) +
        tm_scale_bar(position = c("left","bottom")) +
        tm_credits(text = "Black dots are observed outbreaks","bottom"))}
  else {tm_layout(main.title = paste("Hazard of an ASF case in month ",legend.outside = T) +
      tm_compass(type = "arrow",size = 2) +
      tm_scale_bar(position = c("left","bottom")) +
      tm_credits(text = "Black dots are observed outbreaks",bBox = bounding_Box) +
    tm_polygons(col = "ci_upper",title = "Upper C.I.",size = 0.3) +
    if(!nrow(observed_cases %>% 
             filter(month_case %in% x$tend)) < 1) { tm_shape(observed_cases %>%
                                                               filter(month_case %in% x$tend)) +
        tm_dots() +
        tm_layout(main.title = paste("Upper C.I. of an ASF case in month ","bottom"))}
  else {tm_layout(main.title = paste("Upper C.I. of an ASF case in month ",ncol = 1)
)

tmap_animation(hazard_map,filename = here("output","animations","russia.gif"),width = 1050,height = 1400)

失败 ==Error in tmap_animation(hazard_map,: List item 1 of tm is not a tmap object.

这里有一个可重现的数据框(数据框的前 2 行),可用于生成图像中的绘图。


structure(list(X = c(-4181934.17690532,-4176738.78016592),Y = c(752808.27257769,719098.953544242),region_name = c("Giaginskiy rayon","Koshekhabl'skiy rayon"
),tend = c(2L,2L),bio3 = c(29,30),bio12 = c(725,726),cropped_friction_surface = c(0.006000000052154,0.003000000026077),cropped_pop = c(7.87983798980713,20.3763484954834
),pig_2015_arealweighted = c(9.35486846547738,9.35486846547738
),presence = c("not_present","not_present"),hazard = c(0.00231109081155119,0.00309440873062446),se = c(0.529502669568597,0.487570646463767
),ci_lower = c(0.000801487651917125,0.00116702240832846),ci_upper = c(0.00666403372086964,0.0082049541841101),region_area_log_km = c(13.7759548469193,12.8435709973728),geometry = structure(list(structure(list(list(
    structure(c(-4162732.39440542,-4161105.96952306,-4159996.36412775,-4159213.55533242,-4159715.01656309,-4160134.70498844,-4162926.51113771,-4164778.28946346,-4166775.2098956,-4168546.92346267,-4170921.79976075,-4173295.45203597,-4174647.76734333,-4175581.07652839,-4175966.94876052,-4175816.93855014,-4174968.91167406,-4172901.04053655,-4171950.07691866,-4172019.40541771,-4173170.1031879,-4174819.37993646,-4177000.02673812,-4180511.95780247,-4183271.56375852,-4185514.16969135,-4187239.31457335,-4190594.54833658,-4190794.79051662,-4192467.34075727,-4194152.97253254,-4195476.39535301,-4198193.57364895,-4200081.87386786,-4200841.01808489,-4200309.75829463,-4199611.05983897,-4199526.78645894,-4199379.29220841,-4199563.20500502,-4198802.89695369,-4198556.10200327,-4199004.2222313,-4199596.8696315,-4198912.17456645,-4196389.94190633,-4193898.91434134,-4192125.9099578,-4190747.93599344,-4190059.67906222,-4190296.72390319,-4189986.56522106,-4188937.83535511,-4187918.11767202,-4188125.66979928,-4185733.71822489,-4182756.05318507,-4180391.12589442,-4177507.94858685,-4176299.47169059,-4175254.93629081,-4174909.0314605,-4175405.1719708,-4174434.24072276,-4172172.05595886,-4169481.52139958,-4166733.7602104,-4163374.34750937,-4162732.39440542,738760.914964658,740505.290404627,743161.382549646,745948.573226,750875.896935378,753899.086453953,754372.509278913,754194.615789594,752811.428536641,751801.037010596,751831.740357359,752728.233514525,753795.270766842,756109.240475783,758590.29028058,760536.289798508,760956.39303402,761506.094505848,762381.843550724,763913.443553185,765765.438876718,767328.750570841,768471.159634284,769359.998454208,770289.263304784,771971.740813603,772706.265848129,773807.477292689,772075.234603134,770709.732556304,768604.544863131,768267.942490493,769214.268878146,769135.445280082,767568.490491717,764273.597189936,761758.179592494,761107.236881939,760024.917297383,756854.520941048,755575.458157903,754303.021875323,752817.227283183,751955.493862646,748743.09904174,747953.492588328,747780.259262057,747859.520243115,747034.093615358,745634.61489715,743859.239107245,741225.58524883,737886.478557469,735369.17010286,732857.895381852,733380.610157177,734037.975264369,733255.02013963,733500.01484839,733954.268478057,735400.423073425,737340.465269221,740604.110629702,741802.802909834,741770.443288111,740912.477598853,739766.837417982,736396.158293141,738760.914964658),.Dim = c(69L,2L)))),class = c("XY","MULTIpolyGON","sfg")),structure(list(list(structure(c(-4173456.13939747,-4172997.45249977,-4172148.94665715,-4171217.67501103,-4168781.65188884,-4166324.85077971,-4164480.26482415,-4178309.7888467,-4177246.24092689,-4177098.23472403,-4177644.42167342,-4180132.8524839,-4181814.1484255,-4182558.83391862,-4183591.98700204,-4184659.77061194,-4187127.01497078,-4189204.31290236,-4191339.0846464,-4192329.26766187,-4192485.18426393,-4190959.95417442,-4189440.92419064,-4187449.81104347,-4185699.45742538,-4184008.87604056,-4181735.00503839,-4179860.9310574,-4177632.78683323,-4176288.93235825,-4174529.16272954,-4173835.50595425,-4178336.30415239,-4180229.87282414,-4188204.35486898,-4179496.97438071,-4174739.59575742,-4173756.07960608,-4173456.13939747,712687.768931731,715109.1936317,718522.540162841,721810.319536555,726877.502199857,730552.71996595,733618.834012808,730944.356956924,728350.146681854,724930.945003733,720989.353816073,716972.201584825,713503.497019879,710356.059271399,707374.293460737,705334.282467714,703474.754029596,701784.40815653,700704.330827986,697485.460687304,695354.121734403,692890.806616664,691692.424217377,691605.246229214,691520.517600468,693931.95200127,697663.147945103,700447.728142479,704265.781051318,707310.476483324,709853.278940218,711686.106412449,710685.282420052,703512.018861669,697707.982341893,714558.673011659,714671.14182258,711896.053904727,712687.768931731),.Dim = c(50L,"sfg"))),class = c("sfc_MULTIpolyGON","sfc"),precision = 0,bBox = structure(c(xmin = -4200841.01808489,ymin = 691520.517600468,xmax = -4159213.55533242,ymax = 773807.477292689
),class = "bBox"),crs = structure(list(input = "+proj=aea +lat_1=50 +lat_2=70 +lat_0=56 +lon_0=100 +x_0=0 +y_0=0 +ellps=wgs84 +datum=wgs84 +units=m +no_defs",wkt = "PROJCRS[\"unkNown\",\n    BASEGEOGCRS[\"unkNown\",\n        DATUM[\"World Geodetic System 1984\",\n            ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                LENGTHUNIT[\"metre\",1]],\n            ID[\"epsg\",6326]],\n        PRIMEM[\"Greenwich\",\n            ANGLEUNIT[\"degree\",0.0174532925199433],8901]]],\n    CONVERSION[\"unkNown\",\n        METHOD[\"Albers Equal Area\",9822]],\n        ParaMETER[\"Latitude of false origin\",56,8821]],\n        ParaMETER[\"Longitude of false origin\",8822]],\n        ParaMETER[\"Latitude of 1st standard parallel\",50,8823]],\n        ParaMETER[\"Latitude of 2nd standard parallel\",70,8824]],\n        ParaMETER[\"Easting at false origin\",\n            LENGTHUNIT[\"metre\",1],8826]],\n        ParaMETER[\"northing at false origin\",8827]]],\n    CS[Cartesian,2],\n        AXIS[\"(E)\",east,\n            ORDER[1],\n                ID[\"epsg\",9001]]],\n        AXIS[\"(N)\",north,\n            ORDER[2],9001]]]]"),class = "crs"),n_empty = 0L)),row.names = c(NA,-2L),sf_column = "geometry",agr = structure(c(X = NA_integer_,Y = NA_integer_,region_name = NA_integer_,tend = NA_integer_,bio3 = NA_integer_,bio12 = NA_integer_,cropped_friction_surface = NA_integer_,cropped_pop = NA_integer_,pig_2015_arealweighted = NA_integer_,presence = NA_integer_,hazard = NA_integer_,se = NA_integer_,ci_lower = NA_integer_,ci_upper = NA_integer_,region_area_log_km = NA_integer_
),.Label = c("constant","aggregate","identity"),class = "factor"),class = c("sf","tbl_df","tbl","data.frame"))

生成绘图的完整数据框似乎很大,在这里很有帮助,但如果需要,很乐意添加

单情节的gif在这里,忽略不同的图例:

tmap_gif

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。