plotly and flexdashboard

Hello,
I am using an Rmarkdown file to create a dashboard using Flexdashboard.
Using ggplot only my legend is correct. The following code creates the chart:
p <- ggplot(data = df, aes(x=Timeperiod, y=Value, group = AreaName, colour = AreaName, text = paste("Area name: ", AreaName, "
Time period: ", Timeperiod, "
Rate: ", round(Value,1), "per 100,000"))) +
geom_line() +
geom_point() +
geom_point(data = sti_Q, aes(shape = c(paste(AreaName, qtr, Timeperiod)))) +
theme(axis.text.x = element_text(vjust = 0.5), axis.title.x = element_blank()) +
labs(y = "Crude rate per 100,000 persons all ages", colour = "Area", shape = "") +
guides(shape = guide_legend(order = 2),colour = guide_legend(order = 1)) +
expand_limits(y=0)

Adding plotly:
p <- ggplot(data = df, aes(x=Timeperiod, y=Value, group = AreaName, colour = AreaName, text = paste("Area name: ", AreaName, "
Time period: ", Timeperiod, "
Rate: ", round(Value,1), "per 100,000"))) +
geom_line() +
geom_point() +
geom_point(data = sti_Q, aes(shape = c(paste(AreaName, qtr, Timeperiod)))) +
theme(axis.text.x = element_text(vjust = 0.5), axis.title.x = element_blank()) +
labs(y = "Crude rate per 100,000 persons all ages", colour = "Area", shape = "") +
guides(shape = guide_legend(order = 2),colour = guide_legend(order = 1)) +
expand_limits(y=0)

ggp <- ggplotly(p, tooltip = "text")
ggp %>% config(displaylogo = FALSE, modeBarButtonsToRemove = list("autoScale2d", "resetScale2d","select2d", "lasso2d", "zoomIn2d", "zoomOut2d", "toggleSpikelines", "zoom2d", "pan2d"))

creates the following. See the legend:

Is the reason for this obvious or is it a problem as I am using plotly in flexdashboard. What might be abetter approach to introducing some interactivity in flexdashboard (i.e. tooltips)

Thanks

You could try using the plotly syntax instead of ggplot perhaps?

Thanks williaml,
Useful to be pointed towards this but my data was more complex. In the end I found a fix on Stack Overflow: https://stackoverflow.com/questions/49133395/strange-formatting-of-legend-in-ggplotly-in-r
Thanks for your help though

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.