Skip to content
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

Feature Request - Groups #1

Closed
charliejhadley opened this issue Jul 26, 2016 · 7 comments
Closed

Feature Request - Groups #1

charliejhadley opened this issue Jul 26, 2016 · 7 comments

Comments

@charliejhadley
Copy link

Great library!

I wondered if you had looked to support groups in the future, a la http://visjs.org/examples/timeline/other/groupsPerformance.html

There are few good htmlwidget solutions for Gantt charts I have been able to find, in fact the only solution I've found thus far depends on plotly converting a ggplot2 plot:

timeline_data <- read.csv(file="https://ndownloader.figshare.com/files/5533355")
timeline_data$Start.Date <- as.Date(timeline_data$Start.Date)
timeline_data$End.Date <- as.Date(timeline_data$End.Date)
label_column <- "Prime.Minister"
category_column <- "Political.Party"
earliest_date_by_Prime_Minister <-
  timeline_data[timeline_data$Start.Date == ave(timeline_data$Start.Date, timeline_data$Prime.Minister, FUN =
                                                  min), ]
earliest_date_by_Prime_Minister <-
  earliest_date_by_Prime_Minister[order(
    earliest_date_by_Prime_Minister$Start.Date,
    earliest_date_by_Prime_Minister$Prime.Minister), ]
timeline_data$Prime.Minister <-
  factor(timeline_data$Prime.Minister, levels = rev(as.character(unique(earliest_date_by_Prime_Minister$Prime.Minister))))
timeline_data <- timeline_data[!is.na(timeline_data$End.Date) & !is.na(timeline_data$Start.Date),]
party_colours <- list("Labour" = "#DC241f", "Conservatives" = "#0087DC", "Liberal Democrat" = "#FDBB30")
party_colours <- as.character(party_colours[levels(timeline_data$Political.Party)])
gantt_labeler <- function(start_date = NA, end_date = NA, y_axis = NA, color = NA){
  paste0(
    "Prime Minister: ", y_axis, "</br>",
    "Date Range: ", start_date," to ",end_date,
    "</br>",
    "Political Party: ",color
  )
}
library(ggplot2)
library(plotly)
ggplotly(
  ggplot(
    data = timeline_data,
    aes(
      x = Start.Date,
      xend = End.Date,
      y = eval(as.name(label_column)),
      yend = eval(as.name(label_column)),
      colour = eval(as.name(category_column)),
      text = gantt_labeler(start_date = Start.Date, end_date = End.Date, y_axis = eval(as.name(label_column)), color = eval(as.name(category_column)))
    )
  ) + geom_segment(size = 3) + xlab("Date") + ylab("Prime Minister") + scale_colour_manual(name = "Political Parties",values = party_colours),
  tooltip = "text"
)

image

@daattali
Copy link
Owner

Hi Martin, groups was indeed the only feature I didn't really implement
(for strange reasons that I won't get into). As this is my first ever
htmlwidget package, I wasn't sure how it will be received, but it does
look like people are using it and since you requested group support within
less than a day, it means it's probably useful.

So yes, I'll try to add it to the next CRAN release! I'd also welcome a PR
:)
On Jul 26, 2016 2:55 AM, "Martin John Hadley" notifications@github.com
wrote:

Great library!

I wondered if you had looked to support groups in the future, a la
http://visjs.org/examples/timeline/other/groupsPerformance.html

There are few good htmlwidget solutions for Gantt charts I have been able
to find, in fact the only solution I've found thus far depends on plotly
converting a ggplot2 plot:

timeline_data <- read.csv(file="https://ndownloader.figshare.com/files/5533355")timeline_data$Start.Date <- as.Date(timeline_data$Start.Date)timeline_data$End.Date <- as.Date(timeline_data$End.Date)label_column <- "Prime.Minister"category_column <- "Political.Party"earliest_date_by_Prime_Minister <-
timeline_data[timeline_data$Start.Date == ave(timeline_data$Start.Date, timeline_data$Prime.Minister, FUN =
min), ]earliest_date_by_Prime_Minister <-
earliest_date_by_Prime_Minister[order(
earliest_date_by_Prime_Minister$Start.Date,
earliest_date_by_Prime_Minister$Prime.Minister), ]timeline_data$Prime.Minister <-
factor(timeline_data$Prime.Minister, levels = rev(as.character(unique(earliest_date_by_Prime_Minister$Prime.Minister))))timeline_data <- timeline_data[!is.na(timeline_data$End.Date) & !is.na(timeline_data$Start.Date),]party_colours <- list("Labour" = "#DC241f", "Conservatives" = "#0087DC", "Liberal Democrat" = "#FDBB30")party_colours <- as.character(party_colours[levels(timeline_data$Political.Party)])gantt_labeler <- function(start_date = NA, end_date = NA, y_axis = NA, color = NA){
paste0(
"Prime Minister: ", y_axis, "
",
"Date Range: ", start_date," to ",end_date,
"
",
"Political Party: ",color
)
}
library(ggplot2)
library(plotly)
ggplotly(
ggplot(
data = timeline_data,
aes(
x = Start.Date,
xend = End.Date,
y = eval(as.name(label_column)),
yend = eval(as.name(label_column)),
colour = eval(as.name(category_column)),
text = gantt_labeler(start_date = Start.Date, end_date = End.Date, y_axis = eval(as.name(label_column)), color = eval(as.name(category_column)))
)
) + geom_segment(size = 3) + xlab("Date") + ylab("Prime Minister") + scale_colour_manual(name = "Political Parties",values = party_colours),
tooltip = "text"
)

[image: image]
https://cloud.githubusercontent.com/assets/9363263/17133755/5b0c95f8-531f-11e6-80c6-9eb43e52448d.png


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#1, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6IFGzDJUR_nyxFRHERiLh_tg609hZyks5qZdmKgaJpZM4JU-gC
.

@charliejhadley
Copy link
Author

It's a very nice htmlwidget, and I found it via twittering so definitely making a mark. I looked briefly into how it worked and can guarantee I can't make a PR within the next few months - a basic htmlwidget library of my own is on the roadmap for about my timescale.

Should also say: the timeline/Gantt chart in the googleVis library is still Flash dependent. I take this to mean that Gantt charts like I asked for aren't wildly popular, so shouldn't be considered a high priority request.

@daattali
Copy link
Owner

I've never heard of the term "gantt chart" and a google search for it only returned 2M results so it doesn't look like it's too popular, but nonetheless supporting that kind of visualization would be good. Maybe there's a different more popular name for those kind of charts? Anyway, this issue will be updated when I do tackle this

@pssguy
Copy link

pssguy commented Jul 26, 2016

I'd love it if this could be extended to having a meaningful y axis. Current example I would like to enhance is my soccer site managers section. Had planned to look at plotly wrapper as alternative

@timelyportfolio
Copy link

@daattali I might have some time at the end of the week to take a shot at it if you would like. Just let me know.

@daattali
Copy link
Owner

thanks @timelyportfolio , I don't absolutely need the help (in some other repos I specifically put out a call for help, so I'm not afraid to say when I do!) but I'd definitely appreciate anyone saving me a bit of time by contributing, so please do if you find some time!

@daattali
Copy link
Owner

@timelyportfolio I ended up doing it tonight so you can have more free time on the weekend :)

@martinjhnhadley I added support for groups, but haven't documented it yet. But you can start using it, you should be able to replicate the ggplot2 image you showed us. You can see the example I have on the app (and you can see its source code). See the vis.js docs for more info on groups

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

No branches or pull requests

4 participants