I have made a gantt plot with the vistime library in R and want to reproduce it with plotly.
Here's the result with vistime package
and the result with plotly
The problem is the vistime plot there are dots indicating the end of the case but there are not segments in the plotly, plus the text in the segment is not the same.
Code to reproduce
# import libraries --------------------------------------------------------
library(readxl) # read xlsx files
library(vistime) # gantt charts
library(plotly) # interactive plots
library(RColorBrewer)
# read and manipulate data ------------------------------------------------
mdat = read_excel('gantt_data.xlsx') ; colnames(mdat)
mdat$start = strptime(mdat$start,
"%Y-%m-%d %H:%M:%S")
mdat$complete = strptime(mdat$complete,
"%Y-%m-%d %H:%M:%S")
mdat$start = as.POSIXct(mdat$start,
tz ='GMT',
format =c("%Y-%m-%d %H:%M:%OS"))
mdat$complete = as.POSIXct(mdat$complete,
tz ='GMT',
format =c("%Y-%m-%d %H:%M:%OS"))
# Gantt with vistime ------------------------------------------------------
# Classic palette BuPu, with 4 colors
coul <- brewer.pal(12, "Set3")
# Add more colors to this palette :
n_labels = length(unique(mdat$ActivityID)); n_labels
coul <- colorRampPalette(coul)(n_labels)
mdat$cols <- factor(mdat$ActivityID,
labels = coul)
vistime(mdat,
col.event = 'ActivityID',
col.group = 'CaseID',
col.start = 'start',
col.end = 'complete',
col.color = 'cols',
optimize_y = F,
show_labels = F,
linewidth = 25
) %>%
layout(yaxis=list(fixedrange=TRUE, tickfont=list(size=8),
tickangle=-30,
showgrid = T),
title = "Cases with the highest (lead) time",
plot_bgcolor = "#e5ecf6"
)
# Gantt with plotly -------------------------------------------------------
m <- mdat %>%
mutate(end = coalesce(complete, start)) #works
p <- ggplot(m,
aes(x=start, xend=end, y=CaseID, yend=CaseID, color=ActivityID, group=CaseID)) +
theme(legend.position="none")+ #use ggplot theme with black gridlines and white background
geom_segment(size=8) + #increase line width of segments in the chart
labs(title='Cases with the highest (lead) time"', x='Time', y='CaseID')
ggplotly(p)
# -------------------------------------------------------------------------
and the dataset