Search notes:

R data visualization: bar chart

A most simple example

The most important R function to create a bar chart is barplot:
x11()

heights <- c(  12, 15, 8, 9, 14, 13, 9 )

barplot(heights)


# wait for mouse click or enter pressed
z <- locator(1)
Github repository about-r, path: /graphics/data-visualization/bar-chart/simple.R
You might want to decorate the output with a title and labels.

Naming the bars

With the names argument, it's possible to name the individual bars of the chart:
x11()

heights <- c(  12, 15, 8, 9, 14, 13, 9 )

barplot(
  heights,
  names = c( 'A', 'B', 'C', 'D', 'E', 'F', 'G'  )
)


# wait for mouse click or enter pressed
z <- locator(1)
Github repository about-r, path: /graphics/data-visualization/bar-chart/naming-bars.R

See also

Data visualization with R
R data visualization: bar chart for mean (average) of bins/groups
Creating bar charts with plot() and factors.
Perl module GD::Graph::bar
Data visualization: Bar charts

Index