Skip to content

Add support for geom_dumbbell #1454

Open

Description

@LearningSpoonsR

Add support for geom_dumbbell please :)

Activity

  1. cpsievert commented on Jan 14, 2019

    @cpsievert
    Collaborator

    What package implements it?

  2. kirbymcrae commented on Jan 16, 2019

    @kirbymcrae

    It's part of ggalt.

    Here is the example code:

    
    library(ggplot2)
    
    df <- data.frame(trt=LETTERS[1:5], l=c(20, 40, 10, 30, 50), r=c(70, 50, 30, 60, 80))
    
    ggplot(df, aes(y=trt, x=l, xend=r)) +
      geom_dumbbell(size=3, color="#e3e2e1",
                    colour_x = "#5b8124", colour_xend = "#bad744",
                    dot_guide=TRUE, dot_guide_size=0.25) +
      labs(x=NULL, y=NULL, title="ggplot2 geom_dumbbell with dot guide") +
      theme_minimal() +
      theme(panel.grid.major.x=element_line(size=0.05))
    
    
  3. cpsievert commented on Jan 21, 2019

    @cpsievert
    Collaborator

    Thanks, that geom seems like a fairly straightforward one, please see #1210 (comment) if you're interested in contributing a ggplotly() hook.

  4. thomaszwagerman commented on Jun 14, 2019

    @thomaszwagerman

    Hi all,

    I'm also looking for geom_dumbbell support if possible.

    Although my own code currently throws errors for geom_segment (I suspect for non-ggploty() related reasons), perhaps this is worth trying as an alternative to geom_dumbbell as it is part of ggplot2 and not ggalt.

    Cheers.

  5. thomaszwagerman commented on Jun 17, 2019

    @thomaszwagerman

    Hi all,

    Just though I'd comment an update in case anyone is still following this issue.

    I commented above recommending the use of geom_segment as an alternative to geom_dumbbell, however I am still running into issues.

    I have the following code:

          activity_data_plot <-  ggplot() +
           geom_segment(data = activity_start_end, aes(x = start, xend = end, y = event,
                                                        yend = event, colour = event),
                         size =4, lineend = "round")+
    
    #I have two geom_points here, to have a start and end point similar to geom_dumbbell.
    #This works in ggplotly without the geom_segment lines
            geom_point(data=activity_start_end, aes(x = start, y = event), size =4, stroke = 3,shape = 21, fill = "white", colour = "black")+
            geom_point(data=activity_start_end, aes(x = end, y = event), size =4, stroke = 3, shape = 21, fill = "white", colour = "black") 
    

    I also tried using geom_rect instead of geom_segment:

           #geom_segment can be replaced with geom_rect, but throw the same error
             geom_rect(data = activity_start_end, aes(xmin = start, xmax = end, ymin = event, 
                                                    ymax = event, colour = event), size =4)+
    

    When debugging, the warning message is produced here, which reads as follows:

    Warning: Error in [[: attempt to select less than one element in get1index
    111: eval
    110: eval
    109: with.default
    107: FUN
    106: vapply
    105: FUN
    104: lapply
    103: gg2list
    102: ggplotly.ggplot
    95: func
    82: origRenderFunc
    81: output$activityPlot
    1: runApp

    This occurs after above plot is fed into:

    ggplotly(activity_data_plot, dynamicTicks = TRUE, tooltip =c("y","x")) %>% layout(yaxis = list(tickmode="auto", autorange=TRUE), legend = list(orientation = "h", y=-0.2)) %>% config(displayModeBar = F)

    However this is not where the error seems to occur.

    The dataframe looks like this:

    > activity_start_end
                                       event  id          timesubmit               start                 end
    1                   something happens 1 621 2019-06-13 13:12:06 2019-06-10 19:00:00 2019-06-10 22:00:00
    2                   something happens 2 639 2019-06-13 13:12:38 2019-06-03 17:00:00 2019-06-06 22:00:00
    3                   something happens 3 639 2019-06-13 13:13:14 2019-06-12 09:00:00 2019-06-12 13:00:00
    

    Where I'm trying to plot a line between the start and end times of a certain event, which looks like this in ggplot:
    image

    Not sure what the issue is, and would appreciate any suggestions if anyone has any.

    Many thanks.

  6. robsmith11 commented on Mar 22, 2021

    @robsmith11

    I'm getting the same error with geom_segment:

    ggplotly(ggplot(data) + geom_segment(aes(x=g, xend=g, y=0, yend=n)) + coord_flip(), dynamicTicks=T)
    
      110: eval
      109: eval
      108: with.default
      106: FUN
      105: vapply
      104: FUN
      103: lapply
      102: gg2list
      101: ggplotly.ggplot
       99: renderPlotly [/c/dash/server.R#34]
       98: func
       95: func
       82: origRenderFunc
       81: output$gamesPlot
        1: runApp
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions