Gantt chart (Gantt chart), and often referred to as bar chart or bar graph, is a modern enterprise project management using the most widely icon. It is through the bar to show the progress of the project, timing and other relevant circumstances.
Outside project management, it can also be used to manage learning programs. There Gantt chart drawing tool many, this article describes the use of R-plotly package drawn interactive Gantt chart, save the html link, you can view at any time.
A data preparation
Loading function package, the data is read
library(plotly)
# Read in data
df <- read.csv("GanttChart.csv", stringsAsFactors = F)
# Convert to dates
df$Start <- as.Date(df$Start, format = "%m/%d/%Y")
head(df,3)
Draw two Gantt
The data shown above, only the contents of the task or project Task, the Start start time, duration of data to draw Gantt chart.
# Resource Set The color of the Gantt chart
cols <- RColorBrewer :: brewer.pal ( length ( UNIQUE ( DF $ Resource)), name = "Set3")
DF $ Color <- factor ( DF $ Resource, Labels = cols) initially an empty object # P <- plot_ly () # for each task a line plot, starting time and task duration for ( I in . 1 :( nrow ( DF) - . 1)) { P <- add_trace ( P , the X- =
C ( DF $ the Start [ I], DF $ the Start [ I] + DF $ the Duration [ I]), # from test and terminate Y = C ( I, I), # MODE = "Lines", Line = List ( Color = DF $ color [ I], width = 20 is), color # line plot and a line width set ShowLegend = F., hoverinfo = "text", # suspension information is text information provided text display content # text = Paste (
"Task: ", df$Task[i], "<br>",
"Duration: ", df$Duration[i], "days<br>",
"Resource: ", df$Resource[i]),
evaluate = T ,
xaxis = list(showgrid = F, tickfont = list(color = "#e6e6e6")),
yaxis = list(showgrid = F, tickfont = list(color = "#e6e6e6"),
tickmode = "array", tickvals = 1:nrow(df), ticktext = unique(df$Task),
domain = c(0, 0.9)),
plot_bgcolor = "#333333", # 设置颜色
paper_bgcolor = "#333333"
)
}
Change Layout Information
-
Remove gridlines
-
Display task task
p <- layout(p,
xaxis = list(showgrid = F, tickfont = list(color = "#e6e6e6")),
yaxis = list(showgrid = F, tickfont = list(color = "#e6e6e6"),
tickmode = "array", tickvals = 1:nrow(df), ticktext = unique(df$Task),
domain = c(0, 0.9)),
plot_bgcolor = "# 333333", # the Chart Area Color paper_bgcolor = "# 333333") # the Axis Area Color
NOTE: failing to grasp the insert html interactive method, so the dynamic interaction FIG own run.
more content:
R | survival analysis (1) : survival analysis and presentation drawing KM curve
Nomogram (Nomo Figure) | Logistic, Cox survival analysis results visualization
Forest plot (forest plot) | Cox survival analysis visualization
maftools | tumor mutation TCGA summary data, analysis and visualization
maftools | scratch draw level published oncoplot (waterfall)
ggalluvial | cool Sankey diagram (Sankey), you can also show
ggplot2 | Detailed drawings of the eight basic elements
ggplot2 | ggpubr be "paper" Photo Merge
pheatmap | rainstorm pause, "heat map" incoming! ! !
ggplot2-plotly | make your volcano plot "live" over
ggplot2 | draw KEGG bubble chart
ggplot2 | draw GO enrichment column chart
Drawing series | R-corrplot FIG Related
Drawing series | R-VennDiagram Wayne FIG draw package
R | clusterProfiler- Enrichment Analysis