I have a question how to modify stacked barplot crossing the x axis presented here Stacked barplot crossing the x-axis. I want to set yaxis range from eg.-10 to 10. But when I've used ylim(-10,10) negative values appear on the left and scale_y_continuous(labels=abs) doesn't work (like in: https://i.stack.imgur.com/JwgW9.png). How to set range on yaxis and have positive values on both sides from zero?
Asked
Active
Viewed 278 times
1
-
2Try using limits=c(-10,10) in the scale_y_continuous call – user20650 Mar 29 '14 at 12:52
-
Yes, the problem is that the last call to a function the modifies the y-axis overrides anything set in prior calls. So if you call `ylim(...)` first and then `scale_y_continuous(...)` the settings in `ylim(...)` are lost. If you do it the other way around, call `ylim(...)` last, then you get the limits, but the setting of `labels=abs` is lost. The solution is to put all the changes into one call, as @user20650 says. – jlhoward Mar 29 '14 at 17:45
-
Thank you! Now the code is: scale_y_continuous(labels=abs,limits=c(-10,10)) and it works. It looks so obvious now :). – Alicja Mar 29 '14 at 18:43