Changing hovertext in plotly

Back in 2018, a similar question was raised (see: Is there way to change hovertext in plotly)

However, my issue involves additional formatting of the 'text' parameter within ggplot that causes the plot to become malformed.

The following code demonstrates the problem.

library(plotly)

theData <- filter(txhousing, city == "Abilene")
p <- ggplot(theData) +
  geom_line(aes(date, median, text = paste0(city, ", TX", "<br>", median)))
pp <- ggplotly(p, tooltip = "text")
print (pp)

Notice how the runchart doesn't connect the points anymore, but horizontal lines of points that have the same value are connected. Remove the last 'median' in the 'text =' line and the problem doesn't occur.

one solution is to directly construct your chart in plotly

library(plotly)

theData <- filter(txhousing, city == "Abilene")
plot_ly(
  data=theData,
  x=~date,
  y=~median,
  type="scatter",
  mode="lines",
  text = ~paste0(city, ", TX", "<br>", median),
  hoverinfo = 'text'
)

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

Seems a defect, but not surprising to me that it's an imperfect function

Although that is an option, I have lots of existing ggplot charts in various code development suites that I was planning to just do the single line conversion. Is this not a defect in the ggplot package code?