gg_gantt_chart: Gantt chart

Description Usage Arguments Details Value Author(s) Examples

Description

Creates a Gantt chart with horizontal or vertical lines

Usage

1
2
3
4
5
6
7
8
gg_gantt_chart(data, var, var_levels = NULL, time, status = NULL,
  group = NULL, group_levels = NULL, facet_r = NULL, facet_c = NULL,
  facet_r_levels = NULL, facet_c_levels = NULL, facet_scale = "free",
  facet_space = "free", x_lab = NULL, y_lab = NULL, group_lab = group,
  title = NULL, label_align = "left", label_angle = NULL, grids = "on",
  bw_theme = TRUE, horizontal = TRUE, point_shape_map = if (horizontal) { 
     list(start = 15, end = 16, ongoing = 45) } else {     list(start = 15, end
  = 16, ongoing = 45) }, point_size = 3, point_legend = FALSE)

Arguments

data

Data frame: default dataset to use for plot

var

Character: name of a data column mapped to events/projects

var_levels

Character vector: levels of var, i.e. unique names of all the events/projects

time

Character: name of a data column mapped to the start and end dates of an event/project. For each event/project, both start and end dates should be present in order to draw a line segment, representing the duration of the event/project

status

Character: name of a data column mapped to the status of the date in the same row. This argument, together with point_shape_map, is used to add points and specify the shape of the points at the start and end dates of each event/project. The column of status contains at most three status of an event/project: start, end, and ongoing. Custom phrasing of these three status are permitted as long as names of point_shape_map, if not NULL, match those status phrases.

group

Character: name of a data column mapped to the color of the lines

group_levels

Vector/List: a named vector/list that specifies the levels and labels of group

facet_r

Character: name of a data column mapped to the facet row in panel plot layout. Check facet_grid for more details

facet_c

Character: name of a data column mapped to the facet column in panel plot layout. Check facet_grid for more details

facet_r_levels

Vector/List: a named vector/list that specifies the levels and labels of facet_r

facet_c_levels

Vector/List: a named vector/list that specifies the levels and labels of facet_c

facet_scale

Character: Are scales shared across all facets. Refer to the 'scale' argument in facet_grid. Default 'free' means that scales are not shared

facet_space

Character: Refer to the 'space' argument in facet_grid. Default 'free' means both height and width will vary

x_lab

Character: x-axis label

y_lab

Character: y-axis label

group_lab

Character: group variable label

title

Character: barplot title

label_align

Character: alignment of the event/project labels. If 'left' (default), labels will be left-aligned; if 'center', labels will be center-aligned; if 'right', labels will be right-aligned

label_angle

Character: the orientation angle (in [0, 360]) of the event/project labels on the axis. By default, the label will be perpendicular to the axis

grids

Character: control the grids. If 'on' (default), grids will be drawn; if 'x', only grids on x-axis will be drawn; if 'y', only grids on y-axis will be drawn; if 'off', no grids will be drawn

bw_theme

Logical: If TRUE (default), black-and-white theme will be used. Refer to theme_bw for more details

horizontal

Logical: If TRUE (default), horizontal gantt chart is drawn; if 'FALSE', vertical version is drawn instead

point_shape_map

List/Character vector/Numeric vector: specify points shape mapping to status column. If unnamed, levels of status are used as the names. Names of the list/vector must match the unique values of status column. Values of the list/vector must be valid shape representation. Refer to ggplot2 Quick Reference: shape for more details

point_size

Numeric: size of the points. Must be positive value

point_legend

Logical: If TRUE (default), legend of point shape is included; otherwise, omitted

bar_label_angle

Numeric: the orientation angle (in [0, 360]) of the bar labels on the axis. By default, the label will be perpendicular to the axis

Details

This function relies on ggplot2 package to create a Gantt chart with vertical or horizontal lines. The function supports panel plot layout. Points can be added at the start and end of the lines and the point shape specification is supported through status and point_shape_map arguments together. Refer to the description of the two arguments for more details

Value

An object of class ggplot. Can be directly sent to plot with print

Author(s)

Feiyang Niu (Feiyang.Niu@gilead.com)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
test_df <- data.frame(
    project = rep(paste('Project', 1:10), each = 2),
    time = c(rbind(sample(1:5, 10, replace = TRUE),
                   sample(6:8, 10, replace = TRUE))),
    status = factor(c(rbind(rep('start', 10),
                            c(rep('end', 5), rep('ongoing', 5)))),
                    levels = c('start', 'ongoing', 'end'))
)
gg_gantt_chart(test_df, var = 'project', time = 'time',
               status = 'status', y_lab = '', grids = 'y')
gg_gantt_chart(test_df, var = 'project', time = 'time',
               status = 'status', point_legend = TRUE)

statech/CommonPlots documentation built on May 6, 2019, 1:32 a.m.