R -在制作美国各州热图时遇到麻烦

  • 本文关键字:遇到 麻烦 美国 r
  • 更新时间 :
  • 英文 :


我正在尝试制作本周周二数据的美国各州热图。我有很多麻烦让它工作,我认为这应该只需要几行代码。

  • USMAP是在R中这样做映射的最好方法吗?

  • 是否有一个ggplot的方法来做到这一点,而不是使用usmap包?

  • 我在我的例子中做错了什么?

    library(usmap)
    library(tidyverse)
    nurses <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-05/nurses.csv')
    plot_data <- nurses %>% 
    filter(Year == 2020) %>% 
    select(State, `Total Employed RN`) %>% 
    rename("Total_Employed" = 2)
    # Works with no data
    plot_usmap()
    # Does not work with data ??
    plot_usmap(data = plot_data,
    values = Total_Employed,
    color = "blue") +
    scale_fill_continuous(low = "white",
    high = "blue")
    # The column is real and I can access it
    plot_data %>% 
    mutate(test_column = (1 + Total_Employed))
    # Trying to emulate an example from : https://cran.r-project.org/web/packages/usmap/vignettes/mapping.html
    statepop <- statepop %>% 
    rename(State = 3)
    merged_df <- left_join(plot_data, statepop, by = "State") %>% 
    select(fips, abbr, Total_Employed, State)
    merged_df
    # Still does not work even though data is in the same format
    plot_usmap(data = merged_df,
    values = Total_Employed,
    color = "blue") +
    scale_fill_continuous(low = "white",
    high = "blue")
    

在这个线程的各种答案:https://twitter.com/Indescribled/status/1445234775858368514

我的首选- https://twitter.com/ivelasq3/status/1445242672021606401

相关内容

  • 没有找到相关文章

最新更新