I'm making a column chart of the amount of time I spend on various projects, each one for one of a range of "clients" (actually different "areas" of my job) using the excellent togglr
package to download my tracked time data and ggplot2.
The code I'm using is this: (data dput(SO) output pasted below question)
library("ggplot2")
library("RColorBrewer")
theme_set(theme_bw())
colourCount = 48 #nrow(projects)
getPalette = colorRampPalette(brewer.pal(12, "Paired"))
ggplot(data = SO, aes(x = client, y = time_spent)) +
geom_col(aes(fill = area_project), colour = "black") +
scale_fill_manual(values = getPalette(colourCount)) +
theme(legend.position = "right") +
guides(fill=guide_legend(ncol = 2)) +
ggtitle("From Start to End") #paste("From", date(min(df$start)), " to", date(max(df$stop)))) +
xlab("Functional Area") + ylab("Hours")
Which produces this plot:
What I can't figure out how to do is to make each column it's own palette with different shades for each project.
I.E. I'd like all the boxes in the "0_Admin" column to be different blues, each box in the "1_Monitoring" column to be different greens, etc. The plot above is close, but mostly by coincidence and the number of projects/area. You'll notice for example that "3_Management" projects are both red and orange, and orange shades "bleed" all the way over to "7_Visitor Safety".
Over time, the number of projects will increase overall (but will be a subset when I'm reporting on smaller time periods) so a fully manual scale is not feasible, but the number of Areas will stay the same.
Any thoughts? Hints? Thanks!
SO <- structure(list(client = c("0_Admin", "0_Admin", "0_Admin", "0_Admin",
"0_Admin", "0_Admin", "0_Admin", "0_Admin", "0_Admin", "1_Monitoring",
"1_Monitoring", "1_Monitoring", "1_Monitoring", "1_Monitoring",
"1_Monitoring", "1_Monitoring", "2_Science", "2_Science", "2_Science",
"2_Science", "2_Science", "2_Science", "3_Management", "3_Management",
"3_Management", "3_Management", "3_Management", "3_Management",
"4_EA", "6_Fire", "6_Fire", "7_VisitorSafety", "8_ResConMisc",
"8_ResConMisc", "8_ResConMisc", "8_ResConMisc", "8_ResConMisc",
"8_ResConMisc", "8_ResConMisc", "8_ResConMisc", "8_ResConMisc",
"9_CrossFxn", "9_CrossFxn", "9_CrossFxn", "9_CrossFxn", "Z_Leave",
"Z_Leave", "Z_Leave"),
project = c("Email", "EPM", "Finance",
"HR", "Misc", "OHS", "RCPs", "Time mgmt", "Training", "Amphibians",
"Area burned", "Birds", "Rangeland Health", "Sediment", "Ungulates",
"Water Quality", "Bison GPS", "Bison science advisory group",
"Collaboration", "Corridor Use", "Grassland bird survey", "Misc",
"Beavers", "Bison", "Geese", "HUMP/HIP", "HWC", "Invasive Plants",
"Nest sweeps", "Fire crew", "Fire mgmt plan", "DO response",
"Duty Officer", "Media", "Misc", "Open Data", "Peer discussion",
"RC meeting", "Training", "Travel", "Work planning", "CC meeting",
"Events", "Misc", "Trails", "Appointments", "Stat holiday", "Vacation"
),
time_spent = c(174.709722222222, 15.2483333333333, 26.7827777777778,
127.603611111111, 21.7127777777778, 6.32222222222222, 11.9725,
3.32111111111111, 29.6375, 4.80333333333333, 0.498055555555556,
74.4958333333333, 21.8011111111111, 1.14111111111111, 21.5008333333333,
36.0780555555556, 1.44972222222222, 1.40694444444444, 6.83916666666667,
3.93027777777778, 6.94916666666667, 2, 28.7986111111111, 154.448888888889,
0.684444444444445, 12.5727777777778, 2.98861111111111, 1.89416666666667,
1.75, 21.2725, 11.0122222222222, 2.74333333333333, 0.817777777777778,
10.415, 84.9144444444444, 11.4, 19.7738888888889, 8.84444444444444,
38.7216666666667, 8, 11.6063888888889, 10.5191666666667, 3.41638888888889,
20.8216666666667, 0.298611111111111, 6.74611111111111, 30, 75.5
),
area_project = c("0_Email", "0_EPM", "0_Finance", "0_HR",
"0_Misc", "0_OHS", "0_RCPs", "0_Time mgmt", "0_Training", "1_Amphibians",
"1_Area burned", "1_Birds", "1_Rangeland Health", "1_Sediment",
"1_Ungulates", "1_Water Quality", "2_Bison GPS", "2_Bison science advisory group",
"2_Collaboration", "2_Corridor Use", "2_Grassland bird survey",
"2_Misc", "3_Beavers", "3_Bison", "3_Geese", "3_HUMP/HIP", "3_HWC",
"3_Invasive Plants", "4_Nest sweeps", "6_Fire crew", "6_Fire mgmt plan",
"7_DO response", "8_Duty Officer", "8_Media", "8_Misc", "8_Open Data",
"8_Peer discussion", "8_RC meeting", "8_Training", "8_Travel",
"8_Work planning", "9_CC meeting", "9_Events", "9_Misc", "9_Trails",
"Z_Appointments", "Z_Stat holiday", "Z_Vacation")), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -48L), vars = "client", labels = structure(list(
client = c("0_Admin", "1_Monitoring", "2_Science", "3_Management",
"4_EA", "6_Fire", "7_VisitorSafety", "8_ResConMisc", "9_CrossFxn",
"Z_Leave")), class = "data.frame", row.names = c(NA, -10L), vars = "client", drop = TRUE),
indices = list(0:8, 9:15, 16:21, 22:27, 28L, 29:30, 31L, 32:40, 41:44, 45:47),
drop = TRUE, group_sizes = c(9L, 7L, 6L, 6L, 1L, 2L, 1L, 9L, 4L, 3L), biggest_group_size = 9L)