You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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'. 😉
@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?
Activity
cpsievert commentedon Mar 7, 2018
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
GeomLollipopmethod for theto_basicgeneric that outputs a list of two data frames (similar toGeomSmooth): one with classGeomSegmentand one with classGeomPointmschilli87 commentedon Mar 7, 2018
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'. 😉
jonas-hag commentedon Apr 9, 2018
Hey @mschilli87 have you already started working on it? Otherwise I'd like to give it a try :)
mschilli87 commentedon Apr 10, 2018
@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.
jonas-hag commentedon Apr 17, 2018
@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?


cpsievert commentedon Apr 17, 2018
Awesome!
One option is to set
hoverinfo="none"for the segments.Unfortunately there isn't much we can do about that at the moment (besides using crosstalk, similar to this)
I think ggalt makes more sense, but would work either way
kcbioy commentedon Oct 12, 2021
If no one is working on this, I'd like to give this a go.
jonas-hag commentedon Nov 7, 2021
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