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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745487828, '52.14.17.231', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/graphics/data-visualization/bar-chart/index(89): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78