将每列设置为其自己的调色板

时间:2018-08-25 05:08:33

标签: r ggplot2 colorbrewer geom-col

我正在使用各种出色的togglr来制作我在各种项目上花费的时间的柱形图,每个项目代表一系列“客户”(工作中实际上是不同的“领域”)中的一个软件包以下载我跟踪的时间数据和ggplot2。

我正在使用的代码是这样的:(将数据dput(SO)输出粘贴到问题下方)

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")

是哪个情节?

Time tracking plot

我不知道该怎么做,就是使每个列都是自己的调色板,并且每个项目的阴影都不同。

I.E。我希望“ 0_Admin”列中的所有框都为不同的蓝色,而“ 1_Monitoring”列中的每个框都为不同的绿色,等等。上面的图很接近,但是主要是出于巧合和项目/区域的数量。例如,您会注意到“ 3_Management”项目是红色和橙色,橙色阴影一直“渗色”到“ 7_Visitor Safety”。

随着时间的流逝,项目的数量将总体增加(但是当我报告较小的时间段时,这将是一个子集),因此完全手动的规模是不可行的,但是Areas的数量将保持不变。 >

有什么想法吗?提示?谢谢!

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)

0 个答案:

没有答案