Skip to content

Conversation

trekonom
Copy link
Contributor

This PR proposes a fix to take account of linebreaks in yaxis ticklabels.

At present ggplotly does not take linebreaks in y-axis labels into account when computing the margins. Hence, the left margin is set too wide in that case.

The issue can be illustrated with this reprex:

library(plotly)

d <- data.frame(x = c(1, 2), y = c("dfdfjdfdf\ndjdfkjdfdklj\nsldflkfdlf", "dfdfjdfdf"))

ggplot(d, aes(x, y)) +
  geom_bar(stat = "identity")

ggplotly()

At present this is rendered with a lot of white space to the left of the axis labels:

grafik

With the proposed fix the reprex is rendered like so:

grafik

As a workaround to this issue one can force automargin to do its job by setting the left margin to a small number in the layout options like so:

ggplotly() %>%
    layout(margin = list(l = 0))

@trekonom trekonom marked this pull request as ready for review June 12, 2020 11:17
trekonom and others added 2 commits June 23, 2020 11:42
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
@cpsievert cpsievert merged commit 52552f7 into plotly:master Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants