[英]R usmap - how to show two different colors: one for gradients in positive value while the other show the negative value
Below is my current code for the graph.以下是我当前的图表代码。 How can I make two different colors by having 0 as middle point eg.
如何通过将 0 作为中间点来制作两个不同的 colors,例如。 red in positive number and blue in negative number.
正数为红色,负数为蓝色。
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")
Obviously I din't have your data, so I've made some up.显然我没有你的数据,所以我编造了一些。 You should be able to get what you want with
scale_fill_gradientn
:您应该能够使用
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.