usmap not showing data for some Alaska counties

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

usmap not showing data for some Alaska counties

问题

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

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

# 提取FIPS代码和肥胖率数值
chd_map = chd_map[-c(1,2), c(3,75)]

# 将肥胖率数值转换为数字
chd_map$Adult.obesity.raw.value = as.numeric(chd_map$Adult.obesity.raw.value) * 100

# 重命名FIPS列
colnames(chd_map)[1] = 'fips'

# 绘制数据
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 = '成年肥胖率(2022)', label = scales::comma
  ) +
  labs(title = '图X. 各县肥胖率分布') + 
  theme(panel.background = element_rect(color = 'white', fill = 'white'), legend.position = 'bottom')

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


<details>
<summary>英文:</summary>

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")

[![Figure showing grey counties][1]][1]


  [1]: https://i.stack.imgur.com/GHJbo.png

</details>


# 答案1
**得分**: 0

以下是您要翻译的代码部分:

```R
在找到缺失县的名称后(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 相同。

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")

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


请注意,这是您提供的代码的翻译部分,不包含任何其他内容。

<details>
<summary>英文:</summary>

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")


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


  [1]: https://i.stack.imgur.com/LQv6f.png

</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:

确定