简体   繁体   English

R usmap - 如何显示两个不同的 colors:一个用于正值梯度,另一个显示负值

[英]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.

相关问题 R:用不同的颜色映射正负数 - R: Mapping positive and negative numbers with different colors 确定两列是否在R中包含负值和正值 - Determining if two columns contain either a negative and positive value in R 从R数据框中删除负值和一个正值 - Removing negative values and one positive value from R dataframe Spearman的正r值和负斜率 - Positive Spearman's r value with negative abline 如何将具有负值和正值的列更改为负值加零和正值加零的两列 - how to change a column with both negative and positive value into two columns with negative value plus zero and positive value plus zero 有负值时展开 x 轴,但您想将其显示为正值 - Expand x axis once you have negative value, but you want to show it as a positive value 在 R 的 Highchart 中,如何通过条形图中的负值和正值更改 colors - In Highchart in R how to change colors by negative and positive values in a bar chart 将 colors 分配给 R 条形图中的负值和正值 - Assign colors to negative and positive values in R barplot 如何让 ggplot Heatmap (R) 使用两个 colors? 一种表示填充值介于 -.1 到 .1 之间,另一种表示不表示 - How to get ggplot Heatmap (R) to use two colors? One for between a fill value of -.1 to .1 and one for not 带有两个数据帧的散布直方图,R中一个正负 - Staked histogram with two data frames, one positive and another negative in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM