程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法删除 tmap 数据中的因素大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法删除 tmap 数据中的因素?

开发过程中遇到无法删除 tmap 数据中的因素的问题如何解决?下面主要结合日常开发的经验,给出你关于无法删除 tmap 数据中的因素的解决方法建议,希望对你解决无法删除 tmap 数据中的因素有所启发或帮助;

我开始熟悉在映射中使用 R 并且我目前正在使用 tmap 包。对数据进行子集化时遇到问题。我可以使用 tIDyverse 语法毫无问题地选择各种子集,但我无法删除未使用的级别以确保图例保持合理。

#// load library and data
library(tIDyversE)
library(tmap)
data("World")

#// subset data to only include Africa
tm_africa <- filter(World,conTinent == "Africa") 
tm_shape(tm_africa) + tm_polygons("name")
#> Warning: number of levels of the variable "name" is 177,which is
#> larger than max.categorIEs (which is 30),so levels are combined. Set
#> tmap_options(max.categorIEs = 177) in the layer function to show all levels.
#> Some legend labels were too wIDe. these labels have been resized to 0.62,0.45,0.54,0.59,0.50,0.62,0.61,0.47,0.46,0.63. Increase legend.wIDth (argument of tm_layout) to make the legend wIDer and therefore the labels larger.

无法删除 tmap 数据中的因素


#// remove unused levels for proper legends
#// output suggests levels are indeed dropped
forcats::fct_drop(tm_africa$Name)
#>  [1] Angola               Burundi              Benin               
#>  [4] Burkina Faso         Botswana             Central African Rep.
#>  [7] Cote d'Ivoire        Cameroon             Dem. Rep. Congo     
#> [10] Congo                DjiboutI             Algeria             
#> [13] Egypt                Eritrea              Ethiopia            
#> [16] Gabon                Ghana                Guinea              
#> [19] Gambia               Guinea-Bissau        Eq. Guinea          
#> [22] Kenya                liberia              libya               
#> [25] Lesotho              Morocco              Madagascar          
#> [28] Mali                 Mozambique           Mauritania          
#> [31] Malawi               Namibia              Niger               
#> [34] Nigeria              Rwanda               W. Sahara           
#> [37] Sudan                s. Sudan             Senegal             
#> [40] SIErra Leone         Somaliland           Somalia             
#> [43] Swaziland            Chad                 Togo                
#> [46] Tunisia              Tanzania             Uganda              
#> [49] South Africa         Zambia               Zimbabwe            
#> 51 Levels: Algeria Angola Benin Botswana Burkina Faso Burundi ... Zimbabwe

#// check if levels are removed
#// still LisTing countrIEs from outsIDe Africa
head(levels(tm_africa$Name))
#> [1] "Afghanistan" "Albania"     "Algeria"     "Angola"      "Antarctica" 
#> [6] "ArgenTina"

#// plot again to verify levels have not changed
tm_shape(tm_africa) + tm_polygons("name")
#> Warning: number of levels of the variable "name" is 177,0.63. Increase legend.wIDth (argument of tm_layout) to make the legend wIDer and therefore the labels larger.

无法删除 tmap 数据中的因素

由 reprex package (v0.3.0) 于 2021 年 1 月 18 日创建

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的无法删除 tmap 数据中的因素全部内容,希望文章能够帮你解决无法删除 tmap 数据中的因素所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。