This tile plot shows intensity of coronavirus infection rates for the ten most populous counties in Texas. Tiles with the lightest red had 0% of their county's population with confirmed coronavirus cases on that particular day. And tiles with the darkest red had 0.25% of their county's population with confirmed coronavirus cases on that particular day.
Would it be possible to adjust the scale such that the darkest red is set to, say 50%? There is no such value in the source dataset, just thought it might be more in line with data visualization design principles if we could set the highest intensity colors to a value other than the maximum in the dataset.
For example, it might be interesting to have the darkest red be set to the peak infection rate during the Spanish Flu.
Thanks!
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 »"))
It might have something to do with the scale_fill_gradientn() function, but at most the transformations I've tried just have the darker red colors apply to more values from the dataset, which is kind of the opposite of what I'm looking for.
Thanks!
scale_fill_gradientn(limits = c(-3,3)
In this example, '-3' refers to lower limit, and '3' refers to upper limit.
This will override the default lower and upper limits based on the source dataset.