Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add fix to take account of linebreaks in yaxis ticklabels. #1791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2020
Merged

Add fix to take account of linebreaks in yaxis ticklabels. #1791

merged 5 commits into from
Jun 23, 2020

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
R/ggplotly.R Outdated Show resolved Hide resolved
R/ggplotly.R Outdated Show resolved Hide resolved
R/ggplotly.R Outdated Show resolved Hide resolved
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.