- 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/
好的,所以我编辑了以下... 只需将以下内容放入我的 custom.css #rt-utility .rt-block {CODE HERE} 但是当我尝试改变... 与 #rt-sideslid
在表格 View 中,我有一个自定义单元格(在界面生成器中高度为 500)。在该单元格中,我有一个 Collection View ,我按 (10,10,10,10) 固定到边缘。但是在 tablev
对于我的无能,我很抱歉,但总的来说,我对 Cocoa、Swift 和面向对象编程还很陌生。我的主要来源是《Cocoa Programming for OS X》(第 5 版),以及 Apple 的充满
我正在使用 meta-tegra 为我的 NVIDIA Jetson Nano 构建自定义图像。我需要 PyTorch,但没有它的配方。我在设备上构建了 PyTorch,并将其打包到设备上的轮子中。现
在 jquery 中使用 $.POST 和 $.GET 时,有没有办法将自定义变量添加到 URL 并发送它们?我尝试了以下方法: $.ajax({type:"POST", url:"file.php?
Traefik 已经默认实现了很多中间件,可以满足大部分我们日常的需求,但是在实际工作中,用户仍然还是有自定义中间件的需求,为解决这个问题,官方推出了一个 Traefik Pilot[1] 的功
我想让我的 CustomTextInputLayout 将 Widget.MaterialComponents.TextInputLayout.OutlinedBox 作为默认样式,无需在 XML 中
我在 ~/.emacs 中有以下自定义函数: (defun xi-rgrep (term) (grep-compute-defaults) (interactive "sSearch Te
我有下表: 考虑到每个月的权重,我的目标是在 5 个月内分散 10,000 个单位。与 10,000 相邻的行是我最好的尝试(我在这上面花了几个小时)。黄色是我所追求的。 我试图用来计算的逻辑如下:计
我的表单中有一个字段,它是文件类型。当用户点击保存图标时,我想自然地将文件上传到服务器并将文件名保存在数据库中。我尝试通过回显文件名来测试它,但它似乎不起作用。另外,如何将文件名添加到数据库中?是在模
我有一个 python 脚本来发送电子邮件,它工作得很好,但问题是当我检查我的电子邮件收件箱时。 我希望该用户名是自定义用户名,而不是整个电子邮件地址。 最佳答案 发件人地址应该使用的格式是: You
我想减小 ggcorrplot 中标记的大小,并减少文本和绘图之间的空间。 library(ggcorrplot) data(mtcars) corr <- round(cor(mtcars), 1)
GTK+ noob 问题在这里: 是否可以自定义 GtkFileChooserButton 或 GtkFileChooserDialog 以删除“位置”部分(左侧)和顶部的“位置”输入框? 我实际上要
我正在尝试在主页上使用 ajax 在 magento 中使用 ajax 显示流行的产品列表,我可以为 5 或“N”个产品执行此操作,但我想要的是将分页工具栏与结果集一起添加. 这是我添加的以显示流行产
我正在尝试使用 PasswordResetForm 内置函数。 由于我想要自定义表单字段,因此我编写了自己的表单: class FpasswordForm(PasswordResetForm):
据我了解,新的 Angular 7 提供了拖放功能。我搜索了有关 DnD 的 Tree 组件,但没有找到与树相关的内容。 我在 Stackblitz 上找到的一个工作示例.对比drag'ndrop功能
我必须开发一个自定义选项卡控件并决定使用 WPF/XAML 创建它,因为我无论如何都打算学习它。完成后应该是这样的: 到目前为止,我取得了很好的进展,但还有两个问题: 只有第一个/最后一个标签项应该有
我要定制xtable用于导出到 LaTeX。我知道有些问题是关于 xtable在这里,但我找不到我要找的具体东西。 以下是我的表的外观示例: my.table <- data.frame(Specif
用ejs在这里显示日期 它给我结果 Tue Feb 02 2016 16:02:24 GMT+0530 (IST) 但是我需要表现为 19th January, 2016 如何在ejs中执行此操作?
我想问在 JavaFX 中使用自定义对象制作 ListView 的最佳方法,我想要一个每个项目如下所示的列表: 我搜了一下,发现大部分人都是用细胞工厂的方法来做的。有没有其他办法?例如使用客户 fxm
我是一名优秀的程序员,十分优秀!