首页 > 解决方案 > 如何在分位数中标记 R usmap

问题描述

我用代码生成了一张地图:

plot_usmap(data = df, values = "ServicePerFFS", color = "red") + 
  scale_fill_continuous(name = "ServicePerFFS (2017)", type = "viridis", label = scales::comma) + 
  theme(legend.position = "right")

但是,我想更改分位数的标签。我对这样做的不同方式感兴趣。

 dput(head(df))
    structure(list(abbr = c("AK", "AL", "AR", "AZ", "CA", "CO"), 
    fips = c("02", "01", "05", "04", "06", "08"), full = c("Alaska", 
    "Alabama", "Arkansas", "Arizona", "California", "Colorado"
    ), pop_2015 = c(738432, 4858979, 2978204, 6828065, 39144818, 
    5456574), FFSpop = c(82927, 969116, 593592, 1155335, 5478663, 
    789379), Service = c(413, 7776, 7105, 8856, 64246, 8227), 
    ServicePerFFS = c(4980.28386412146, 8023.80726352676, 11969.5009366703, 
    7665.30919603405, 11726.5836573631, 10422.116625854)), row.names = c(NA, 
6L), class = "data.frame")

标签: r

解决方案


像这样?

df$ServicePerFFS <- percent_rank(df$ServicePerFFS)

plot_usmap(data = df, values = "ServicePerFFS", color = "red") + 
  scale_fill_continuous(name = "ServicePerFFS (2017)", type = "viridis", label = scales::comma) + 
  theme(legend.position = "right")

在此处输入图像描述


编辑:

plot_usmap(data = df, values = "ServicePerFFS", color = "red") + 
  scale_fill_continuous(name = "ServicePerFFS (2017)", type = "viridis", breaks = as.numeric(quantile(df$ServicePerFFS)),labels = paste(round(quantile(df$ServicePerFFS),2),names(quantile(df$ServicePerFFS)), "of ServicePer FFS")) + 
  theme(legend.position = "right") 

推荐阅读