Skip to content

FR: geom_lollipop #1210

Open
Open

Description

@mschilli87

I want to suggest a feature and I would be willing to give it a shot myself and opening a PR, but I would like to know if there is interest first.


I would like to see geom_lollipop implemented in plotly.

It is an alternative to geom_bar that basically combines two layers: geom_point and geom_segment.
For ggplot, geom_lollipop is implemented in the ggalt package.


Here is a minimal example:

library(ggalt)
library(plotly)

mtcars <- data.frame(car=rownames(mtcars), mtcars)

base.plot <- ggplot(mtcars, aes(car, mpg))

bar.plot <- base.plot + geom_bar(stat="identity")
bar.plot + ggtitle("static bar plot")
ggplotly(bar.plot + ggtitle("reactive bar plot"))

lollipop.plot <- base.plot + geom_lollipop()
lollipop.plot + ggtitle("static lollipop plot")
#This does not work:
#ggplotly(lollipop.plot + ggtitle("reactive lollipop plot"))

lollipop.plot <- base.plot + geom_segment(aes(xend=car), yend=0) + geom_point()
lollipop.plot + ggtitle("static lollipop plot")
# Now it works:
ggplotly(lollipop.plot + ggtitle("reactive lollipop plot"))
# But hints could be improved (also show point hints on segment hover).

Please let me know if there is any interest and maybe some hints how/where to start.

Activity

  1. cpsievert commented on Mar 7, 2018

    @cpsievert
    Collaborator

    This feature would be great for a first time contributor. I've actually outlined how we convert geoms using ggalt as an example --

    https://plotly-book.cpsievert.me/translating-custom-ggplot2-geoms.html
    https://github.com/hrbrmstr/ggalt/blob/master/R/geom2plotly.r

    As your example suggests, you could likely implement a GeomLollipop method for the to_basic generic that outputs a list of two data frames (similar to GeomSmooth): one with class GeomSegment and one with class GeomPoint

  2. mschilli87 commented on Mar 7, 2018

    @mschilli87
    Author

    Thx @cpsievert for the helpful reply.
    If nobody else picks this up before easter, I'll give it a shot. Until then I'll probably be too busy to 'play around'. 😉

  3. jonas-hag commented on Apr 9, 2018

    @jonas-hag

    Hey @mschilli87 have you already started working on it? Otherwise I'd like to give it a try :)

  4. mschilli87 commented on Apr 10, 2018

    @mschilli87
    Author

    @jonas-hag: No. Something else came up and I won't have time before mid-May or so. So feel free to pick this up.

  5. jonas-hag commented on Apr 17, 2018

    @jonas-hag

    @cpsievert I'm done with the functionality as outlined by you, but I've noticed two behaviours of two tools I'm not sure if it is ok. When using "compare data on hover", the data is shown both for the point and the segment. Also, when using the selection tools the unselected points are transparent, but the segments are not and they seem to be in the foreground. See the attached files. If it is not ok, do you have a hint where to look at to change this behaviour?

    Also I was wondering if to_basic.GeomLollipop should be included into plotly or into ggalt?
    select_data
    show_data_hover

  6. cpsievert commented on Apr 17, 2018

    @cpsievert
    Collaborator

    Awesome!

    When using "compare data on hover", the data is shown both for the point and the segment.

    One option is to set hoverinfo="none" for the segments.

    Also, when using the selection tools the unselected points are transparent, but the segments are not and they seem to be in the foreground.

    Unfortunately there isn't much we can do about that at the moment (besides using crosstalk, similar to this)

    Also I was wondering if to_basic.GeomLollipop should be included into plotly or into ggalt?

    I think ggalt makes more sense, but would work either way

  7. kcbioy commented on Oct 12, 2021

    @kcbioy

    If no one is working on this, I'd like to give this a go.

  8. self-assigned this
    on Oct 12, 2021
  9. jonas-hag commented on Nov 7, 2021

    @jonas-hag

    Sorry, somehow I didn't follow up with the needed changes. @kcbioy feel free to use the code I've already written, you find it here: jonas-hag@1719359

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions