Open alanocallaghan opened 7 years ago
This should simply involve checking the axis position in the ggplot object and changing the axis position in the ggplot object appropriately:
https://community.plot.ly/t/move-axis-labels-to-top-right/534
Scale position is available in ggplot$scales$scales
. In the instance posted above it is ggplot$scales$scales[[2]]$position
but I don't know if that's generally true.
ggplot$scales$scales[[1]] tends to be the colour scale (if present) while the others are only present if modified. The quick and dirty solution would be to apply across them and return TRUE if position
equals "right" or "bottom" but this is not robust
Pulling in the information itself is trivial during ggplotly, eg:
## If scales are top or right, move them
x_scale <- scales$get_scales("x")
if (!is.null(x_scale) && !is.null(x_scale$position) && x_scale$position == "top") gglayout$xaxis$side == "top"
y_scale <- scales$get_scales("y")
if (!is.null(y_scale) && !is.null(y_scale$position) && y_scale$position == "top") gglayout$xaxis$side == "right"
However, this does not affect the output (the y-axis is not shown if side==="right")
Actually, on further testing, this fix may work. I will try some extra testing and submit a PR if needed
@alanocallaghan I wonder if the fix has been put in place.
Doesn't look that way to me
ggplot 2.2.0 newly added right/top axis placements. ggplotly does not currently respect the axis placement set in the ggplot objects in the resultant html