So I am trying to create a temperature gradient by colors based on temperature values. I have the following example:
> dput(head(temp_data))
structure(list(Date = structure(c(726624000, 726710400, 726796800,
726883200, 726969600, 727056000), tzone = "UTC", class = c("POSIXct",
"POSIXt")), Row = c(1, 2, 3, 4, 5, 6), High = c(29, 22, 29, 35,
33, 33), Low = c(16, 18, 20, 25, 13, 17), Average = c(22.5, 20,
24.5, 30, 23, 25)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
This provides me with a table of dates and temperature values. I have ten different quantile values:
> quantile(temp_data$Average,prob=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9),type=1)
10% 20% 30% 40% 50% 60% 70% 80% 90%
24.0 31.0 36.5 40.5 48.5 54.0 61.0 68.0 74.0
I want to create a column that pastes a string color name based on the temperature value. For example, if the average is less than 24.0 then I want the value in the new column to be "navy", and I want to have a different color for each of the quartile ranges. Is there a good way to write this? Do I need a for loop?