usmap not showing data for some Alaska counties

huangapple go评论99阅读模式
英文:

usmap not showing data for some Alaska counties

问题

我正在绘制阿拉斯加各县的肥胖率数值,但有些县是灰色的,不代表该县的数值。我无法弄清楚这些灰色县的FIPS代码,或者它们为什么是灰色的。我认为我为它们拥有的FIPS代码是不正确的,但即使是内部地图的人口数据也将它们显示为灰色。

  1. # 读取数据
  2. chd_map = read.csv(file = 'https://www.countyhealthrankings.org/sites/default/files/media/document/analytic_data2022.csv',
  3. header = TRUE, sep = ",")
  4. # 提取FIPS代码和肥胖率数值
  5. chd_map = chd_map[-c(1,2), c(3,75)]
  6. # 将肥胖率数值转换为数字
  7. chd_map$Adult.obesity.raw.value = as.numeric(chd_map$Adult.obesity.raw.value) * 100
  8. # 重命名FIPS列
  9. colnames(chd_map)[1] = 'fips'
  10. # 绘制数据
  11. plot_usmap(
  12. data = chd_map,
  13. size = 0.1,
  14. regions = 'counties',
  15. include = c('AK'),
  16. values = 'Adult.obesity.raw.value',
  17. color = 'black') +
  18. scale_fill_continuous(type = 'viridis', name = '成年肥胖率(2022)', label = scales::comma
  19. ) +
  20. labs(title = '图X. 各县肥胖率分布') +
  21. theme(panel.background = element_rect(color = 'white', fill = 'white'), legend.position = 'bottom')

[![显示灰色县的图][1]][1]

  1. <details>
  2. <summary>英文:</summary>
  3. I am plotting obesity values for counties in Alaska, but some counties are grey, and not representing the values for that county. I am not able to figure out the FIPS codes for the counties that are grey, or why they are grey. I assume the FIPS codes I have for them are incorrect, but even the internal upmaps population data shows them as grey.

read in data

chd_map = read.csv(file =
'https://www.countyhealthrankings.org/sites/default/files/media/document/analytic_data2022.csv',
header = TRUE, sep=",")

pull out FIPS codes and obesity values

chd_map = chd_map[-c(1,2),c(3,75)]

make obesity values numeric

chd_map$Adult.obesity.raw.value = as.numeric(chd_map$Adult.obesity.raw.value) * 100

rename fips column

colnames(chd_map)[1] = 'fips'

plot data

plot_usmap(
data = chd_map,
size = 0.1,
regions = "counties",
include = c('AK'),
values = "Adult.obesity.raw.value",
color = "black") +
scale_fill_continuous(type = "viridis", name = "Percentage of Adults with Obesity (2022)", label = scales::comma
) +
labs(title = "Figure X. Distribution of Obesity Prevalence by County") +
theme(panel.background = element_rect(color = "white", fill = "white"), legend.position = "bottom")

  1. [![Figure showing grey counties][1]][1]
  2. [1]: https://i.stack.imgur.com/GHJbo.png
  3. </details>
  4. # 答案1
  5. **得分**: 0
  6. 以下是您要翻译的代码部分:
  7. ```R
  8. 在找到缺失县的名称后(Chugach Census Area [02063] 和 Copper River Census Area [02066]),我发现这些县是在2019年创建的。Valdez-Cordova Census Area 县在2019年分割成这两个新县,而我的数据是在2019年之前创建的,所以仍然包括了 Valdez-Cordova Census Area 县。最终,我在数据中创建了 Chugach Census Area 和 Copper River Census Area,它们的数值与 Valdez-Cordova Census Area 相同。
  9. valdez_obesity = chd_map$Adult.obesity.raw.value[chd_map$fips == '2261']
  10. chugach = data.frame(2063, valdez_obesity)
  11. names(chugach) = c('fips', 'Adult.obesity.raw.value')
  12. copper = data.frame(2066, valdez_obesity)
  13. names(copper) = c('fips', 'Adult.obesity.raw.value')
  14. obesity_map_data = rbind(obesity_map_data, chugach, copper)
  15. obesity_map_data = obesity_map_data[-which(obesity_map_data$fips == 2261),]
  16. plot_usmap(
  17. data = chd_map,
  18. size = 0.1,
  19. regions = "counties",
  20. include = c('AK'),
  21. values = "Adult.obesity.raw.value",
  22. color = "black"
  23. ) +
  24. scale_fill_continuous(type = "viridis", name = "Percentage of Adults with Obesity (2022)", label = scales::comma) +
  25. labs(title = "Figure X. Distribution of Obesity Prevalence by County") +
  26. theme(panel.background = element_rect(color = "white", fill = "white"), legend.position = "bottom")

[![fixed_map][1]][1]

  1. 请注意,这是您提供的代码的翻译部分,不包含任何其他内容。
  2. <details>
  3. <summary>英文:</summary>
  4. After finding the names to the missing counties (Chugach Census Area [02063] &amp; Copper River Census Area [02066], I found out that these counties were created in 2019. The Valdez-Cordova Census Area county was split in 2019 into these two new counties, and my data was created pre-2019, so it still had the Valdez-Cordova Census Area county. I ended up creating Chugach Census Area &amp; Copper River Census Area in the data with the same values as Valdez-Cordova Census Area.

valdez_obesity = chd_map$Adult.obesity.raw.value[chd_map$fips == '2261']

chugach = data.frame(2063,valdez_obesity)
names(chugach) = c('fips', 'Adult.obesity.raw.value')

copper = data.frame(2066,valdez_obesity)
names(copper) = c('fips', 'Adult.obesity.raw.value')

obesity_map_data = rbind(obesity_map_data, chugach, copper)

obesity_map_data = obesity_map_data[-which(obesity_map_data$fips == 2261),]

plot_usmap(
data = chd_map,
size = 0.1,
regions = "counties",
include = c('AK'),
values = "Adult.obesity.raw.value",
color = "black") +
scale_fill_continuous(type = "viridis", name = "Percentage of Adults with Obesity (2022)", label = scales::comma
) +
labs(title = "Figure X. Distribution of Obesity Prevalence by County") +
theme(panel.background = element_rect(color = "white", fill = "white"), legend.position = "bottom")

  1. [![fixed_map][1]][1]
  2. [1]: https://i.stack.imgur.com/LQv6f.png
  3. </details>

huangapple
  • 本文由 发表于 2023年2月10日 04:24:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404058.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定