Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating histogram horizontally in r

Tags:

plot

r

histogram

Can anyone help me how to rotate histogram just by 90 degrees in r? I know there is an option (horiz=T) in boxplot but I have no idea if there is a similar one for the histogram.

like image 688
Soheil Avatar asked Jun 12 '18 06:06

Soheil


2 Answers

I think you have to use hist with barplot to do it like below (its straight from documentation), you can check it here ?layout.

x <- pmin(3, pmax(-3, stats::rnorm(50)))
xhist <- hist(x, breaks = seq(-3,3,0.5), plot = FALSE)
barplot(xhist$counts, axes = TRUE, space = 0, horiz=TRUE, xlab= "Counts", ylab="Bins")
like image 111
PKumar Avatar answered Sep 19 '22 01:09

PKumar


If you use ggplot2, you can use coord_flip():

    # here with @PKumar data
    x <- pmin(3, pmax(-3, stats::rnorm(50)))
    library(ggplot2)
    qplot(x, geom="histogram",binwidth = 0.3) + coord_flip()

enter image description here

like image 43
s__ Avatar answered Sep 18 '22 01:09

s__