← Back to R Course | Chapter 10: Data Visualization | Lesson 3 of 7

barplot()

In this page:

  1. barplot()

barplot()

barplot(heights) draws a bar chart from a vector of values (or a table() result), one bar per value, useful for comparing categorical counts or totals. names.arg labels each bar. It's the standard way to visualize categorical/count data, as opposed to hist() which is for continuous numeric distributions.

Note: barplot(table(x)) is a common combo: tabulate a categorical vector, then chart the counts directly.

Example: barplot()

markup
sales <- c(Jan = 100, Feb = 150, Mar = 120)

print(sales)
cat("barplot(sales) would draw one bar per month with these heights\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.