0

I have the datset below. I provide only 50 rows even though the issue begins from 1000 rows and later but then the dataset is too big to display it here.

pr59<- structure(list(case_id = c("WC4120721", "WC4120667", "WC4120689", 
"WC4121068", "WC4120667", "WC4120666", "WC4120667", "WC4121068", 
"WC4120667", "WC4121068", "WC4121068", "WC4120666", "WC4120721", 
"WC4120666", "WC4120666", "WC4120721", "WC4121068", "WC4120721", 
"WC4120667", "WC4121354", "WC4121068", "WC4120666", "WC4121354", 
"WC4121354", "WC4121354", "WC4120721", "WC4120667", "WC4121068", 
"WC4121483", "WC4121655", "WC4121354", "WC4121011", "WC4121302", 
"WC4121781", "WC4120958", "WC4120721", "WC4121352", "WC4121211", 
"WC4121354", "WC4121405", "WC4121569", "WC4121661", "WC4121328", 
"WC4121808", "WC4121494", "WC4120689", "WC4121859", "WC4121833", 
"WC4121834", "WC4121360"), lifecycle = c(110, 110, 110, 110, 
120, 110, 130, 120, 10, 130, 10, 120, 120, 130, 10, 130, 15, 
10, 20, 110, 30, 0, 120, 130, 10, 30, 0, 0, 110, 110, 20, 110, 
110, 110, 110, 0, 110, 110, 0, 110, 110, 110, 110, 110, 110, 
10, 110, 110, 15, 110), action = c("WC4120721-CN354877", "WC4120667-CN354878", 
"WC4120689-CN356752", "WC4121068-CN301950", "WC4120667-CSW310", 
"WC4120666-CN354878", "WC4120667-CSW308", "WC4121068-CSW303", 
"WC4120667-CSW309", "WC4121068-CSW308", "WC4121068-CSW309", "WC4120666-CSW310", 
"WC4120721-CSW310", "WC4120666-CSW308", "WC4120666-CSW309", "WC4120721-CSW308", 
"WC4121068-CSW404", "WC4120721-CSW309", "WC4120667-CSW404", "WC4121354-CN354927", 
"WC4121068-CSW421", "WC4120666-C-SUB-DT", "WC4121354-CSW303", 
"WC4121354-CSW308", "WC4121354-CSW309", "WC4120721-CSW404", "WC4120667-CSW415", 
"WC4121068-CSW415", "WC4121483-CN356753", "WC4121655-CN301288", 
"WC4121354-CSW404", "WC4121011-CN358282", "WC4121302-CN301294", 
"WC4121781-CN354089", "WC4120958-CN353543", "WC4120721-CSW415", 
"WC4121352-CN355038", "WC4121211-CSW270", "WC4121354-CSW410", 
"WC4121405-CN354751", "WC4121569-CSW270", "WC4121661-CN301287", 
"WC4121328-CN355026", "WC4121808-CN303310", "WC4121494-CN354545", 
"WC4120689-CSW304", "WC4121859-CN354089", "WC4121833-CN303318", 
"WC4121834-CSW404", "WC4121360-CN356995"), activity = c("Forged Wire, Medium (Sport)", 
"Forged Wire, Medium (Sport)", "Forged Wire, Medium (Sport)", 
"Forged Wire, Medium (Sport)", "BBH-1&2", "Forged Wire, Medium (Sport)", 
"TCE Cleaning", "SOLO Oil", "Tempering", "TCE Cleaning", "Tempering", 
"BBH-1&2", "BBH-1&2", "TCE Cleaning", "Tempering", "TCE Cleaning", 
"CPL", "Tempering", "CPL", "Forged Wire, Medium (Sport)", "TCE for Lacquering", 
"Subcontracting Duratin", "SOLO Oil", "TCE Cleaning", "Tempering", 
"CPL", "Lacquering", "Lacquering", "Forged Wire, Medium (Sport)", 
"Needle Point", "CPL", "Needle Point", "Needle Point", "Brazing Machines", 
"Brazing Machines", "Lacquering", "Forged Wire, Medium (Sport)", 
"Big Manual", "Nickel Barel", "Forged Wire, Medium (Sport)", 
"Big Manual", "Needle Point", "Forged Wire, Medium (Sport)", 
"Brazing Machines", "Forged Wire, Large (Sport)", "SOLO Salt", 
"Brazing Machines", "Brazing Machines", "CPL", "Forged Wire, Medium (Sport)"
), resource = c("3419", "3216", "3409", "3201", "C3-100", "3216", 
"C3-080", "C3-030", "C3-090", "C3-080", "C3-090", "C3-100", "C3-100", 
"C3-080", "C3-090", "C3-080", "C4-040", "C3-090", "C4-040", "3210", 
"C4-210", NA, "C3-030", "C3-080", "C3-090", "C4-040", "C4-150", 
"C4-155", "3205", "5417", "C4-040", "5501", "5201", "7748", "7725", 
"C4-150", "3206", NA, "C4-100", "3403", NA, "5417", "3206", "7714", 
"3107", "C3-040", "7748", "7708", "C4-040", "3203"), timestamp = structure(c(-62042010952, 
-62010323872, -61884118792, -61821087232, -61821025132, -61789534972, 
-61789520332, -61789494952, -61757940232, -61757925652, -61757895952, 
-61694827552, -61694808292, -61663337152, -61663307452, -61663297792,-61663267192, -61631716792, -61631705632, -61631702212, -61631699992, 
-61631652052, -61568570152, -61537087252, -61537057552, -61505477992, 
-61442400112, -61442396992, -61442357152, -61410876172, -61410862072, 
-61410799072, -61379220292, -61347689452, -61347639772, -61316169592, 
-61316168872, -61316168032, -61316164552, -61284589912, -61253008912, 
-61253007532, -61252996012, -61252962832, -61252942252, -61221457852, 
-61221449332, -61221416572, -61221411472, -61189947712), tzone = "Europe/Istanbul", class = c("POSIXct", 
"POSIXt")), .order = 1:50), row.names = c(NA, -50L), class = c("eventlog", 
"log", "tbl_df", "tbl", "data.frame"), case_id = "case_id", activity_id = "activity", activity_instance_id = "action", lifecycle_id = "lifecycle", resource_id = "resource", timestamp = "timestamp")

From here I try:

library(processmapR)
library(bupaR)
pr59 %>% dotted_chart(x = "absolute", y = "start") %>%plot

and with the 1000 rows dataset I get:

Insufficient values in manual scale. 45 needed but only 35 provided.
Run `rlang::last_error()` to see where the error occurred.

Then I try to create and pass my own palette with as many colors as needed:

# count the needed levels of a factor
number <- length(unique(pr59$activity))

library(RColorBrewer)
n <- number
qual_col_pals = brewer.pal.info[brewer.pal.info$category == 'qual',]
col_vector = unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))



pr59 %>% dotted_chart(x = "absolute", y = "start") %>%plot+ 
  scale_fill_manual(values=col_vector[1:number])

but still get the same error.

firmo23
  • 7,490
  • 2
  • 38
  • 114
  • I've edited a typo in your post `buparR` instead of `bupaR`. Now it works. You might want to add that `dotted_chart` isn't part of that package, but part of `library(processmapR)` :) – harre Sep 06 '22 at 11:12

1 Answers1

1

This is a hack solution inspired by : https://stat.ethz.ch/pipermail/r-help/2008-August/171291.html

In this hack I show how I can dictate the (in this example case) 15 colour values utilised.

I would recommend that the proper way to address this is to raise an issue on the appropriate github issue tracker at https://github.com/bupaverse/processmapR/issues

library(processmapR)

col_vector <-  function() rep(c("red","green","blue"),5)

unlockBinding("col_vector", getNamespace("processmapR"))
assign("col_vector", col_vector, getNamespace("processmapR"))

dotted_chart(pr59,x = "absolute", y = "start")
Nir Graham
  • 2,567
  • 2
  • 6
  • 10
  • thanks that works with 15 instead of 5 cause I have 45 activities but then I get only 3 colors. How can I create col_vector with as may fators as I have? – firmo23 Sep 06 '22 at 11:18
  • its a proof of concept, showing it can be whatever you would want it to be. Do you need more help than that ? – Nir Graham Sep 06 '22 at 11:19
  • as I understand I have to create a col_vector as function with as many distinct colors as I need,based on your answer – firmo23 Sep 06 '22 at 11:21
  • exactly right; in the long term, having the package itself give you options to do it more elegantly would be best than this approach; but we cant have you stuck can we :) – Nir Graham Sep 06 '22 at 11:23
  • @NirGraham: Great hack - much more easy to approach than having to edit the package itself and reload. – harre Sep 06 '22 at 11:30