Skip to content

ggplotly drops labels applied to scale_y_discrete with geom_segment #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
charliejhadley opened this issue Dec 17, 2015 · 1 comment
Closed
Labels

Comments

@charliejhadley
Copy link
Contributor

Issue described

ggplotly drops labels applied to scale_y_discrete with geom_segment.

This pattern is useful where geom_segments 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:

image

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)

image

@cpsievert
Copy link
Collaborator

This should be fixed in f1900cc. Let us know if you still have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants