plot - creating mirrored barplots with distinct scales in ggplot2 in R -


i have follow nice question:

how create bar plot 2 variables mirrored across x-axis in r?

these answers show how make mirrored barplots in ggplot2 in r values positive , negative. question is: if want use distinct scales , down bars both positive? example if bar condition 1 , down bar condition 2, , both bars represent values between 1 , 100. want direction of bar signify different conditions on these without committing negative values. possible in ggplot2? thank you

you can change label using scale_y_continuous():

library(ggplot2)  dat <- data.frame(   group = rep(c("above", "below"), each=10),   x = rep(1:10, 2),   y = c(runif(20, 0, 100)) )  dat$y[dat$group=="below"] <- -dat$y[dat$group=="below"]  ggplot(dat, aes(x=x, y=y, fill=group)) +    geom_bar(stat="identity", position="identity") +    scale_y_continuous(breaks=seq(-100,100,by=50),labels=abs(seq(-100,100,by=50))) 

if don't 50, can change by.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -