-
Notifications
You must be signed in to change notification settings - Fork 631
Closed
Labels
Description
Issue described
ggplotly
drops labels
applied to scale_y_discrete
with geom_segment
.
This pattern is useful where geom_segment
s are to be ordered by an auxiliary variable in order to cope with labels
with tied sorting scores, see http://stackoverflow.com/a/32333974/1659890.
Steps to replicate
Using ggplot2 generate the following plot:
Code is as follows:
data.to.plot <- structure(list(Project.Short.Name = c("ORDS Maturity", "ORDS Uptake",
"ORDS ELS", "StaaS", "HFS Diversification", "Matrix Replacement",
"TONE"), Project.Start.Date = structure(c(1346457600, 1349049600,
1406851200, 1406851200, 1412035200, 1414800000, 1414800000), class = c("POSIXct",
"POSIXt"), tzone = "GMT"), Project.End.Date = structure(c(1406764800,
1388448000, 1438300800, 1438300800, 1443657600, 1435622400, 1443571200
), class = c("POSIXct", "POSIXt"), tzone = "GMT"), IT.Board = structure(c(5L,
5L, 6L, 3L, 4L, 7L, 7L), .Label = c("Bodleian Libraries", "Education Board",
"Infrastructure", "Internal", "JISC", "Research", "Unknown"), class = "factor"),
projectID = structure(c(17L, 16L, 15L, 14L, 13L, 12L, 11L
), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
"20", "21", "22", "23"), class = "factor")), .Names = c("Project.Short.Name",
"Project.Start.Date", "Project.End.Date", "IT.Board", "projectID"
), class = c("tbl_df", "data.frame"), row.names = c(NA, -7L))
data.to.plot <-
data.to.plot[order(data.to.plot$Project.Start.Date, data.to.plot$Project.Short.Name),]
## == with factor
base <-
ggplot(data.to.plot, aes(
x = Project.Start.Date, y = projectID, color = as.factor(IT.Board)
))
gantt <- {
base +
scale_y_discrete(breaks = data.to.plot$projectID, labels = data.to.plot$Project.Short.Name) +
geom_segment(aes(xend = Project.End.Date, y = projectID, yend = projectID), size = 5)
}
gantt
Note the use of projectID as breaks for the y axis, to which I provide labels via scale_y_discete
.
Providing the above ggplot to ggplotly
removes the nicely formatted labels on the y-axis, as well as the ordering:
ggplotly(gantt)