Ggplotly: Axis labels overlap tick text

When I create a plot with ggplot, everything looks great. When I use ggplotly to add interactivity to the plot, the axis labels overlap with the tick text. Here's a small example:

df <- mtcars
df$car <- rownames(df)  #intentionally making example with long text
p <- ggplot(data = df, aes(x = car, y = hp)) + 
  geom_bar(stat = "identity") +
  labs(title="Horsepower by car model") +
  xlab("Make and model of car") +
  ylab("Horsepower of car") +
  theme(legend.position="none",
        axis.text.x=element_text(angle=90,vjust = 0.5))
ggplotly(p)

If you simply view p, everything looks fine, but ggplotly(p) results in axis labels that overlap the tick text.
Any suggestions? I've seen similar questions on StackOverflow but no real solutions.
Thanks!

I haven't played around with this much, but you might want to peruse the issues in the plotly repo.

I seem to remember that the developer of plotly reckoned he had about an 80% compatibility to ggplot2, but would need help to bridge the gap further.

Thanks, Mara! I didn't find a solution there but saw some helpful information for other issues.

2 Likes