r - R usmap - 如何显示两种不同的颜色:一种用于正值渐变,另一种显示负值
问题描述
以下是我当前的图表代码。如何通过将 0 作为中点来制作两种不同的颜色,例如。正数为红色,负数为蓝色。
plot_usmap(data = df2, values = "diffProviderPerFFS", color = "white") +
scale_fill_continuous(name = "Provider Per 1000 FFS(2017-2016)", low="light green",high="dark green", label = scales::comma) +
theme(legend.position = "right")
解决方案
显然我没有你的数据,所以我编造了一些。你应该能够得到你想要的scale_fill_gradientn
:
library(usmap)
df2 <- usmap::statepop
df2$diffProviderPerFFS <- runif(nrow(df2), -0.2, 0.5)
plot_usmap(data = df2, values = "diffProviderPerFFS", color = "white") +
scale_fill_gradientn(name = "Provider Per 1000 FFS(2017-2016)",
colours = c("red", "white", "forestgreen"),
breaks = c(-0.2, 0, 0.2),
label = scales::comma) +
theme(legend.position = "right")
推荐阅读
- django - 如何使特定模型字段从另一个模型动态化
- python - 在没有 Pandas 的情况下制作频率表时值不正确
- sql - 使用 regex 和 hive sql 在每 7 个字符后插入逗号
- docker - 每当我(重新)启动容器时,是否有一种简单的方法可以自动运行脚本?
- java - 计算 2 的 k 次方
- fortran - 在并行随机数生成期间无法分配数组时的 OpenMP 段错误
- c# - 我正在实现处理与 UTC 之间的转换的静态方法 - 这是否不必要?
- java - 如何向数组列表中的现有元素添加信息?
- azure-sql-database - SQL Azure - 聚集索引碎片
- r - “Clogit”创建了意外和NA因子,并删除了原始因子