R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
The bar chart uses rectangular bars to visualize data. Bar charts can be displayed horizontally or vertically. The length or length of the bars corresponds to the values they represent.
Use the barplot()
function to draw a vertical bar chart:
x
variable represents values in the x-axis (A,B,C,D)y
variable represents values in the y-axis (2,4,6,8)barplot()
function to create a bar chart of the valuesnames.arg
defines the names of each observation in the x-axisUse col
parameter to change the color of the bars:
To change the texture of the bar, use the density
parameter:
Use the width
parameter to change the width of the bars:
If you want the bars to be horizontal rather than vertical, use horiz = TRUE
: