Plot bars extending on both sides of the Y-axis in R

r
datavisualization

#1

Hello,

I want to plot bars on the Y-axis extending on both the sides.
Suppose I have a vector v which I want to plot.

v<-c(20, 40, 60, 120, 140, 180)

and I want my y-axis to be at x=100, instead of x=0 and then the values less than 100 to be marked to the left of the y-axis using bars and those greater than 100 to the right. How can I get such a barplot?

Thanks.


#2

hello @Aditya_Sharma,

you can use the following piece of code:

x <- c(30,50,70,120,150)
x_100 <- data.frame(x=seq_along(x),
                    y=x-100)
y_br <- seq(-75,50,25)
ggplot(x_100,aes(x=x,y=y)) + geom_bar(stat="identity") + 
        coord_flip() + scale_y_continuous(breaks=y_br,labels=y_br+100)