0

I am working in flexdashboards using rbokeh to create dynamic interactive graphs and charts on a series of health related dashboards.

My current dilemma revolves around adding a line to a stacked bar chart with mapped color values and having it show up in the legend.

That bar chart is working flawlessly.

But when I add a pair of ab-lines to separate regions of the x-axis where a change in methods of collection occur, I cannot find a way to get the line to show up in the mapped legend.

Any attempt to coerce it returns NO CHART at all...

Completely stumped and would love some help!

CODE:

 figure(title= "Confirmed & Probable Cases by Year",tools =c("pan","box_zoom", "reset", "save"), width= 1650, height =950, legend_location='top_left',toolbar_location = "above")%>%
          ly_bar(x=Year, y= count, position='stack', data=probConf, width=.9, hover=TRUE, legend=TRUE, fill_alpha=.7, color=Classification) %>%
          ly_abline(v=17.5, color = "red",  width =1, alpha=.7)%>%
          ly_abline(v=13.5, color = "red",  width =1, alpha=.7, legend ="Change in Case Definition")%>%
          set_palette(discrete_color = pal_color(c( "#336699","#339999")))%>%
          x_axis(label ='Year', grid=FALSE)%>%
          y_axis(label ='Cases',grid=FALSE)

With this: , legend ="Change in Case Definition" in there, I get NO CHART at all, just white.

With ly_abline(v=13.5, color = "red", width =1, alpha=.7)%>% I get a nice chart with no lines on the legend, as in the photograph below. example of legend without ab-lines

With: ly_abline(v=13.5, color = "red", width =1, alpha=.7, legend = TRUE)%>%

I get no chart at all (but no error code, just a vast expanse of white)

bigreddot
  • 33,642
  • 5
  • 69
  • 122
sconfluentus
  • 4,693
  • 1
  • 21
  • 40

1 Answers1

0

Unfortunately currently in rbokeh (as of v0.5.1) legends that contain mapped attributes and custom legends cannot be mixed. To accomplish this right now you could instead of using ly_bar(), use the lower level ly_rect() with a custom legend to draw the rectangles for each bar color.

Ryan
  • 192
  • 9
  • Thank you for the reply. I started down the path you suggest, it got muddy. So, I cheated instead! I extruded the ly_bar, then opened a graph I had with ly_points and a similar line in it using Notepad++ and used 'find' to see what it would look like to place a line in a legend, copied that code, moved it to the same space in my bar graph, figured out, based on the color of the line, what the id was, copied that and dropped it into the new legends code. Hit save, fired it up and I have a flawless legend. While I was in there I change the "variable" and "value" from the hovers as well. – sconfluentus Jun 17 '17 at 04:31