Hello.
I'm new to R, so please forgive any knowledge gaps.
In the data frame returned from the below, each row represents an operation done in a theatre, where "Location" is the operating theatre name, "Date" is the date of the operation, "Type" is whether the operating session was scheduled for full day/AM/PM, and "Order" specifies the order in which each patient was scheduled onto the operating list.
I'm trying to create a stacked bar graph to illustrate the order of patients booked onto each operating list, which I've currently accomplished with the x-axis being "Mins" and y-axis being "Type". This results in my y-axis being three bars wide (one bar for AM, PM and Full-Day).
I would like to consolidate the current y-axis into a single bar, which I've so far only managed to do in Excel in and am now trying to achieve the same thing in R where I'm much less competent! To do it, I need to change the "Order" column so that cases in the "PM" continue on the count from any cases completed in the "AM" provided that the Date/Location both match.
You can see that rows 4-9 of the below data frame represent the operations completed on "2023-01-03" in "Loc2", with the "Order" of AM cases in rows 4-7 increasing by one incrementally. Then, the the count resets for the 2 cases in the PM seen in rows 8-9. Instead of this happening, I would like the PM count to continue so that these are seen as cases 5 and 6 respectively (as shown in the "Correct" column... which contains the solution I'm trying to arrive at).
Any help really appreciated.
Thanks.
Date <- as.Date(c("2023-01-06","2023-01-06","2023-01-06","2023-01-03","2023-01-03","2023-01-03","2023-01-03",
"2023-01-03","2023-01-03","2023-01-04","2023-01-04","2023-01-04"))
Location <- c("Loc1","Loc1","Loc1","Loc2","Loc2","Loc2","Loc2","Loc2","Loc2","Loc2","Loc2","Loc2")
Type <- c("Full_Day","Full_Day","Full_Day","AM","AM","AM","AM","PM","PM","AM","PM","PM")
Order <- c("1","2","3","1","2","3","4","1","2","1","1","2")
Correct <- c("1","2","3","1","2","3","4","5","6","1","2","3")
Mins <- as.integer(c("10","20","30","40","50","60","70","80","90","100","110","120"))
df <- data.frame(Date, Location, Type, Order, Correct, Mins)