-
Notifications
You must be signed in to change notification settings - Fork 631
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
ggplotly - axis titles still overlapping with labels when converting faceted plot #1224
Comments
I believe automargins only account for axis titles/labels, not annotations, which is currently the only way to implement axis titles for facetted plots |
+1. I tried to fix this issue based on this post but wasn't successful. |
I'm also having issues with faceted plots when converting from ggplot to ggplotly. Does anyone have any solutions? |
Correction: that post https://stackoverflow.com/questions/42763280/r-ggplot-and-plotly-axis-margin-wont-change I mentioned does provide a solution, you may just have to play around a bit with the numbers, and determine which label you want to move. |
Note that |
Based on the post that @Nova-Scotia mentioned, I created a simple function that can make it less of a hassle if you have multiple plots that you are creating:
you can pipe your ggplotly output into this function so you don't have to name each plot you make in order to adjust the axis labels |
still relatively new to coding so I might be completely misunderstanding something, but it seems to me that ggplots are now constructed differently and that the gg[['x']][['layout']][['annotations']][[1]][['y']] hack no longer works... Seems to me that p[["theme"]][["text"]] controls the x-axis text, but none of them adjust the y=positioning. |
The layout_ggplotly annotations method doesn't really work for all screen sizes, which is what I'd like to do so that we can integrate ggplotly with my shiny apps. It'd be amazing if this was able to be fixed |
I noticed this function works correctly only when x and y axis titles exist. If either of those is missing -- for example, as a result of |
Props to @cpsievert @Nova-Scotia @jfernandez903 - all very helpful! When using layout_ggplotly <- function(gg, x = -0.1, y = -0.05, x_legend=1.05, y_legend=0.95, mar=list(l=50, r=150)){
# The 1 and 2 goes into the list that contains the options for the x and y axis labels respectively
gg[['x']][['layout']][['annotations']][[1]][['y']] <- x
gg[['x']][['layout']][['annotations']][[2]][['x']] <- y
gg[['x']][['layout']][['annotations']][[11]][['x']] <- x_legend # the legend title was the 11-th list element in my case!
gg[['x']][['layout']][['legend']][['y']] <- y_legend
gg[['x']][['layout']][['legend']][['x']] <- x_legend
gg %>% layout(margin = mar)
} Still a bit fiddly and you'll likely have to play with the coordinate values. More generally |
It appears #1975 fixes this (please open a new issue if you're still struggling with it) |
The issue with axis titles overlapping with axis labels, fixed in the latest version of plotly, appears to still be present when using ggplotly to convert a faceted ggplot.
When converting an unfaceted ggplot, the new
automargin=TRUE
attribute works perfectly:However, when adding a facet, the old issue of overlap between axis titles and labels persists:
Thanks,
Henry
For reference, the original plotly issue and related fix:
plotly/plotly.js#1504
plotly/plotly.js#2243
The text was updated successfully, but these errors were encountered: