- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用 tmap 包在密度图中绘制 1950 年的世界人口。
我手动将人口数据分成 22 个类别,并为每个类别填充不同的颜色。
我的代码是:
library(tmap)
data(World)
map <- tm_shape(World)+
tm_fill("1950",
title = "Population class",
breaks = c(0, 100 ,200, 300, 400, 500, 600, 700, 800, 900,
1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800,
1900, 2000, 3000, 4000),
textNA = "No data",
colorNA = "white",
palette = "topo")+
tm_borders()+
tm_layout("World Density Population Map")
tm_style_classic()
current.mode <- tmap_mode("plot")
map
Error: Invalid palette
dput(df) <- structure(list(name = structure(c(1L, 3L, 4L, 5L, 6L, 14L, 7L, 11L, 13L, 15L, 16L, 17L, 8L, 18L, 20L, 23L, 24L, 25L, 26L, 27L, 21L, 190L, 28L, 29L, 146L, 31L, 19L, 33L, 34L, 35L, 32L, 37L, 201L, 40L, 42L, 43L, 46L, 47L, 48L, 134L, 49L, 58L, 50L, 52L, 53L, 55L, 56L, 22L, 59L, 61L, 65L, 67L, 68L, 71L, 69L, 70L, 73L, 74L, 75L, 76L, 77L, 60L, 78L, 80L, 79L, 203L, 81L, 82L, 108L, 83L, 84L, 85L, 86L, 87L, 88L, 90L, 91L, 93L, 44L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 51L, 103L, 104L, 106L, 105L, 107L, 57L, 173L, 109L, 110L, 111L, 115L, 116L, 113L, 119L, 120L, 121L, 124L, 45L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 136L, 141L, 174L, 142L, 144L, 145L, 160L, 147L, 148L, 149L, 54L, 9L, 150L, 231L, 151L, 152L, 153L, 154L, 158L, 138L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 170L, 89L, 214L, 171L, 172L, 175L, 176L, 177L, 178L, 179L, 202L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 233L, 189L, 191L, 194L, 241L, 200L, 196L, 205L, 237L, 206L, 207L, 208L, 209L, 210L, 211L, 213L, 215L, 216L, 217L, 223L, 218L, 219L, 220L, 221L, 222L, 212L, 66L, 224L, 41L, 225L, 226L, 227L, 30L, 229L, 230L, 232L, 180L, 239L, 240L, 238L, 143L, 117L, 2L, 112L, 156L, 63L, 72L, 159L, 62L, 140L, 155L, 197L, 234L, 36L, 38L, 193L, 192L, 235L, 64L, 157L, 199L, 236L, 12L, 135L, 195L, 161L, 10L, 114L, 204L, 118L, 137L, 169L, 122L, 123L, 228L, 92L, 139L, 39L, 198L), .Label = c("Afghanistan", "Africa", "Albania", "Algeria", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Asia", "Australia", "Australia/New Zealand", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia (Plurinational State of)", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Caribbean", "Central African Republic", "Central America", "Central Asia", "Chad", "Channel Islands", "Chile", "China", "China, Hong Kong SAR", "China, Macao SAR", "China, Taiwan Province of China", "Colombia", "Comoros", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Curacao", "Cyprus", "Czech Republic", "Dem. People's Rep. of Korea", "Dem. Republic of the Congo", "Denmark", "Djibouti", "Dominican Republic", "Eastern Africa", "Eastern Asia", "Eastern Europe", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Europe", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "High-income countries", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Lao People's Dem. Republic", "Latin America and the Caribbean", "Latvia", "Least developed countries", "Lebanon", "Lesotho", "Less developed regions", "Less developed regions, excluding China", "Liberia", "Libya", "Lithuania", "Low-income countries", "Lower-middle-income countries", "Luxembourg", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Melanesia", "Mexico", "Micronesia", "Micronesia (Fed. States of)", "Middle-income countries", "Middle Africa", "Mongolia", "Montenegro", "More developed regions", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Northern Africa", "Northern America", "Northern Europe", "Norway", "Oceania", "Oman", "Other less developed countries", "Pakistan", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Polynesia", "Portugal", "Puerto Rico", "Qatar", "Republic of Korea", "Republic of Moldova", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Lucia", "Samoa", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South-Central Asia", "South-Eastern Asia", "South Africa", "South America", "South Sudan", "Southern Africa", "Southern Asia", "Southern Europe", "Spain", "Sri Lanka", "St. Vincent and the Grenadines", "State of Palestine", "Sub-Saharan Africa", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Tajikistan", "TFYR Macedonia", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United Republic of Tanzania", "United States of America", "United States Virgin Islands", "Upper-middle-income countries", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela (Bolivarian Republic of)", "Viet Nam", "Western Africa", "Western Asia", "Western Europe", "Western Sahara", "World", "Yemen", "Zambia", "Zimbabwe"), class = "factor"), `1950` = c(7752.118, 1263.171, 8872.247, 4354.882, 46.301, 2895.997, 17150.335, 8177.344, 6936.445, 79.088, 115.614, 37894.68, 1353.506, 210.995, 8628.489, 176.795, 3089.649, 2661.293, 412.533, 53974.726, 68.918, 89.793, 48.001, 7250.999, 17527.243, 2308.923, 7745.003, 4432.716, 4466.498, 13736.997, 178.066, 1326.653, 8075.81, 2502.314, 6142.899, 544112.923, 7561.863, 12340.899, 156.334, 15.141, 807.726, 12183.661, 959.489, 3850.295, 5919.997, 494.014, 8902.619, 2255.221, 4268.27, 2364.65, 3470.162, 2199.897, 225.536, 18128.034, 1142.15, 1100.998, 288.993, 4008.299, 41879.607, 25.479, 60.268, 62.001, 473.3, 3527.004, 271.372, 931.926, 69786.246, 4980.878, 33.05, 7566.002, 76.676, 209.999, 59.65, 3146.073, 3093.651, 406.562, 3221.277, 1487.235, 1973.998, 9337.723, 142.656, 376325.205, 69543.319, 17119.263, 5719.191, 2913.093, 1257.971, 46598.602, 2630.131, 1402.896, 82199.47, 6702.996, 448.861, 6076.757, 10549.469, 19211.386, 152.25, 1740, 1682.916, 1334.618, 733.942, 1949, 930.026, 1113.382, 2567.402, 296.001, 196.482, 4083.554, 2953.871, 6109.907, 73.715, 4708.425, 311.997, 222.001, 660.491, 493.254, 28012.558, 780.2, 2341.003, 394.738, 8985.99, 6313.29, 456.418, 485.274, 8483.321, 10027.047, 100.184, 38.066, 64.824, 47.695, 1908.001, 1294.993, 2559.703, 37859.745, 3265.278, 32, 37542.38, 859.66, 1708.192, 1473.245, 7727.735, 18580.487, 24824.013, 8416.969, 535.429, 433.398, 2218, 24.999, 248.111, 16236.292, 102798.657, 2186.187, 82.783, 67, 60, 3121.336, 2476.638, 6732.256, 36.322, 1944.001, 1022.098, 3436.574, 24809.903, 1473.094, 2264.081, 13683.162, 2746.854, 28069.737, 2582.929, 5733.944, 13.766, 214.999, 273, 7009.913, 4668.088, 3413.329, 1531.502, 20710.356, 1395.458, 47.22, 645.628, 69.59, 3605.31, 21238.496, 1211, 5158.193, 37297.652, 1254.444, 20897.237, 50616.012, 102.235, 7649.766, 157813.04, 26.795, 4284.457, 2238.506, 6945.397, 5481.977, 82.102, 4402.32, 2316.95, 2525149.312, 812988.79, 1712160.522, 228901.723, 168843.911, 171614.868, 666585.791, 549089.107, 12681.946, 66922.702, 26400.57, 49221.876, 15587.911, 70768.664, 17075.654, 38028.823, 164900.344, 511574.182, 50957.44, 220170.535, 78029.913, 108632.979, 142255.68, 10085.345, 2199.497, 113739.434, 1516435.967, 1394017.757, 195724.555, 179679.847, 1158315.256, 155.093, 242.011, 130103.438, 768893.01, 824937.314, 800383.367, 1593830.324, 18130.895, 493443.287)), .Names = c("name", "1950"), class = "data.frame", row.names = c(NA, -241L))
最佳答案
假设您使用的是 World
来自 tmap
的数据集包裹。您的代码存在三个问题。首先,没有名为 1950
的列.表示人口密度的列是pop_est_dens
.二、假设pop_est_dens
是您要绘制的列,breaks
太大了,因为最大值只有 1200 左右。第三,topo
不是有效的 palette
姓名。
因此,我将您的代码修改如下。
library(tmap)
data(World)
map <- tm_shape(World)+
tm_fill("pop_est_dens",
title = "Population class",
breaks = c(0, 100 ,200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200),
style = "fixed",
textNA = "No data",
colorNA = "white",
palette = "Reds")+
tm_borders() +
tm_layout("World Density Population Map")
map
关于r - 如何使用 tmap 中的自定义中断来调整调色板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49423007/
是否可以在 tmap 创建的 map 上包含多个 tm_compass()? 我知道您可能不太需要,但假设您想展示不同的指南针类型。使用 spData 包中的 nz 我尝试将每个新指南针添加为附加层,
有没有办法动态防止 tmap 中图例中的重叠值? 拿这个例子: library(tmap) data("World") tm_shape(World) + tm_polygons("HPI", n=7
我正在尝试创建一个函数来映射特定州学区的不同变量。但是我在格式化图例时遇到了一些问题。目前我已经列出了适合 map 的最佳方式(水平),但一些文本被切断(低于平均贫困率),我想在图例中的数字标签中添加
我正在尝试创建一个函数来映射特定州学区的不同变量。但是我在格式化图例时遇到了一些问题。目前我已经列出了适合 map 的最佳方式(水平),但一些文本被切断(低于平均贫困率),我想在图例中的数字标签中添加
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。
我正在使用 tMap 组件。我有一个默认模式为“dd-MM-yyyy”的日期字段。我只需要插入一个空白值。我试过 '01-01-1900',"",TalendDate.getCurrentDate()
我想使用库 Tmap 在 R 的国家 map 上绘制学区。我使用了 official website 中的 shapefile , 国家教育统计中心,用于学区边界。请注意,我使用的是 2019 文件而
当栅格中只有一个值时,我想调整用 tmap 绘制的栅格的基本颜色。 这是一个非常简单的可重现示例: library(raster) library(tmap) a <- raster(matrix(s
第一次在 stackoverflow 上发帖。我一直在学习使用 tmap,并且已经为我需要的等值线图获取了几乎所有内容。然而,我似乎无法找到答案的画龙点睛是让图例标题比下面的文字更大。也想让它变得大胆
我做了一张 map unsing tmap使用 leaflet 包含在 Shiny 的应用程序中.我大致有我想要的:基于 SpatialPolygonsDataFrame 的带有填充颜色的专题 map
我想用 tmap 包在密度图中绘制 1950 年的世界人口。 我手动将人口数据分成 22 个类别,并为每个类别填充不同的颜色。 我的代码是: library(tmap) data(Wo
我正在尝试在 tmap 图中添加一些文本标签。 library(tmap) library(raster) jnk <- getData("GADM",country="IND",level=2) m
我是编程新手,目前正在参加使用 R 的介绍性空间分析类(class)。以下代码生成下面包含的 tmap。 如何将每个 tmap 的标题居中,并将图例放置在右上角而不将 map 本身放在上面? 非常感谢
我有一张使用 tmap 库生成的拥挤 map ,我在 中使用参数 legend.show = FALSE 关闭了图例>tm_layout() 函数。 我想知道的是:有没有办法自己为这张 map 生成图
我不确定如何或是否可以通过以下方式调整关键图例。考虑这个例子: library(tmap) data(Europe) my_map % st_as_sf() %>% # from sf pack
我有这个代码: tm_shape(usa, bbox = bbox, projection = map.crs)+ tm_borders(col = "grey", lwd = 1) + tm
我有一张使用 tmap 库生成的拥挤 map ,我在 中使用参数 legend.show = FALSE 关闭了图例>tm_layout() 函数。 我想知道的是:有没有办法自己为这张 map 生成图
我有一个 TALEND ETL 作业,我正在尝试稍微修改它。 在其中一个 tMap 中,我有一个如下所示的表达式: row.regulation.equals("Reg200806.s3.2a") |
我有这个代码: tm_shape(usa, bbox = bbox, projection = map.crs)+ tm_borders(col = "grey", lwd = 1) + tm
我正在使用 Talend 来准备数据件。 我想使用 tMap 组件将字符串与列的内容进行比较,并创建一个变量以存储在数据库中。问题在于==运算符没有给出正确的结果(例如: row2.recipient
我是一名优秀的程序员,十分优秀!