1

is it possible to "mirror" the y axis with R plotly ? I would like to do something similar to this, but with a mirrored y-axis, in order to plot 2 by 2 some data, one replicate one the regular yaxis, and the other on the mirrored axis (that would prevent me to convert a half of my data to negative values).

Also, if possible, I want the bars to be on the same place (one right under the other), not on two distinct sides like showed in the link.

Thanks in advance.

Micawber
  • 707
  • 1
  • 5
  • 19
  • As you alluded to in your question, this could be easily done if values are made negative to force them on the "mirrored" side. And, if bars are in the same category, or if no option is set to split bars by some category, then they should be on top of each other. That example shows them split for each year, because they are colored by cost category. – creutzml Mar 12 '18 at 15:10
  • So there is no other way than using negative values ?. I was thinking about creating a second yaxis, which would be reversed and then placed under the x-axis. Until now I got this reversed second y axis, but I can't figure how to place it properly under the xaxis – Micawber Mar 12 '18 at 15:12
  • 1
    I suppose you could play around with `facet_wrap` and `theme` options to get your desired result. So you would create the data with an indicator "Above" or "Below," facet on that indicator, minimize spacing between plots through theme options, flip the bars on the bottom graph by passing `desc(yvar)` on the "Below" graph... But you may lose Plotly functionality, because this will all cause you to build the plot as a ggplot object first. – creutzml Mar 12 '18 at 15:18
  • 1
    That seems rather complicated, but I'll try that for now. Thanks. – Micawber Mar 12 '18 at 15:22
  • If it's the label for the negative trick that bothers you, you could also just change the tick labels to show positive values instead (within the `scale_y_continuous` option). Consider this post for a working example: https://stackoverflow.com/questions/17732165/creating-mirrored-barplots-with-distinct-scales-in-ggplot2-in-r?lq=1 – creutzml Mar 12 '18 at 15:29
  • Cool ! Thank you – Micawber Mar 12 '18 at 15:31

0 Answers0