Sixth Chapter Basic Graphics
6.1 Bar Chart
A bar chart shows the distribution (frequency) of category variables by vertical or horizontal bars. Function: Barplot (height)
6.1.1 Simple Bar Chart
6.1.2 Push-Masonry bar and Group bar charts
If the height is a matrix instead of a vector, the drawing result will be a stacked bar chart or a grouped bar chart. If Beside=false (the default), each column in the matrix will generate a bar in the graph, and the values in each column will give the height of the stacked "sub-bar". If beside=true, each column in the matrix represents a grouping, and the values in each column are tied instead of stacked.
6.1.3 Mean bar chart
Bar charts are not necessarily based on count data or frequency data. You can use the data consolidation function and pass the results to the Barplot () function to create a bar chart that represents the mean, median, and standard deviation.
6.1.4 fine-tuning of the bar chart
As the number of bars increases, the labels of the bars may begin to overlap. You can use the parameter cex.names to reduce the font size. Specifying it as a value less than 1 reduces the size of the label. The optional parameter Names.arg allows you to specify a character vector as the label name for the bar. You can also use graphical parameters to assist in adjusting text intervals.
6.1.5 Spine-like chart
Before we end the discussion of bar charts, let's look at a special bar chart called a Spine chart (Spinogram). The spikes are re-scaled for stacked bar charts so that each bar has a height of 1 and the height of each segment is expressed as a scale. A spine chart can be drawn by the function spine () in a VCD package
Library (VCD)
Attach (arthritis)
Counts<-table (treatment,improved)
Spine (counts,main= "spinogaram example")
Detach (Athritis)
6.2 Pie Chart
Pie charts can be created by the following functions: Pie (X,labels)
where x is a nonnegative numeric vector representing the area of each sector, while labels is a character vector that represents each sector label.
R in Action reading notes (3)-sixth chapter: Basic graphics