Horizontal Bar Chart
ggplot2: geom_col() + coord_flip() · Package: ggplot2 · Variables: 1 categorical + 1 numerical
WHAT IS A HORIZONTAL BAR CHART?
A horizontal bar chart flips the standard bar chart on its side, with categories on the y-axis and values extending horizontally. This orientation is particularly useful when category labels are long (like country names or product descriptions) since they read naturally from left to right. Horizontal bars are also the go-to choice for ranked or sorted data — such as "top 10 products by revenue" — because the eye naturally follows the ranked order from top to bottom. In R with ggplot2, create horizontal bars by adding coord_flip() to a standard geom_col() chart.
BEST FOR
- · Many categories (10-30)
- · Long category labels
- · Top-N lists
- · Ranked data
AVOID WHEN
- · Very few categories
- · Time-series data
R + GGPLOT2 CODE EXAMPLE
df <- data.frame(car = rownames(mtcars)[1:10], mpg = mtcars$mpg[1:10]) ggplot(df, aes(x = reorder(car, mpg), y = mpg)) + geom_col(fill = "#ff6a00") + coord_flip() + labs(title = "MPG by Car", x = NULL, y = "MPG")
Run this code now
Paste the code above into RChat and see the horizontal bar chart rendered instantly in your browser.