【发布时间】:2020-05-18 17:14:16
【问题描述】:
此图块显示了德克萨斯州人口最多的十个县的冠状病毒感染率强度。最浅红色的瓷砖在当天有 0% 的县人口确诊冠状病毒病例。最深红色的瓷砖在当天有 0.25% 的县人口确诊冠状病毒病例。
是否可以调整比例以将最深的红色设置为 50%?源数据集中没有这样的值,只是认为如果我们可以将最高强度颜色设置为数据集中最大值以外的值,它可能更符合数据可视化设计原则。
例如,将最深的红色设置为西班牙流感期间的感染率峰值可能会很有趣。
谢谢!
library("tidyverse")
library("ggthemes")
library("RColorBrewer")
# may16 is a modified dataset from the Texas Department of State Health Services: (1) it's been transposed from wide to long, (2) it's been mutated to include a new "Rate" column, (3) "Date" column has been transformed from type <chr> to <date>, and (4) it's .csv instead of .xlsx.
# may16 modified dataset includes 18,035 rows and 5 columns: (1) "County" <chr>, (2) "Population" <int>, (3) "Date" <date>, (4) "Cases" <int>, and (5) "Rate" <dbl>
# top10 is a list of the names of the ten most populous counties in Texas.
may16 %>% filter(County %in% top10)
%>% ggplot(aes(Date, County, fill=Rate))
+ geom_tile(color="grey50")
+ theme_minimal()
+ theme(panel.grid=element_blank())
+ scale_fill_gradientn(colors=RColorBrewer::brewer.pal(9, "Reds"))
+ geom_vline(xintercept=as.Date("2020-05-01"))
+ labs(title = "Coronavirus Infection Rates", subtitle = "for 10 most populous counties", caption = "Source: Texas Department of State Health Services 2020", x="", y="")
+ geom_text(aes(as.Date("2020-04-25"),"Travis",label="Texas re-opens »"))
这可能与 scale_fill_gradientn() 函数有关,但我尝试的最多转换只是将较深的红色应用于数据集中的更多值,这与我的情况相反正在寻找。
谢谢!
【问题讨论】:
标签: r dataset data-visualization gradient legend-properties