First, let’s create the frequency and relative frequency distributions from the body part data in Table 1.

library(mosaic)
Table1 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter2/Table1.csv")
Table1_Freq <- data.frame(tally(~Location,data=Table1))
Table1_RelFreq <- data.frame(tally(~Location,data=Table1,format="prop"))

Bar Graphs from Summarized Data

Using the summarized data from the frequency table, we can create a bar graph of the frequencies.

To create a frequency bar graph, use the following syntax:

barplot(Frequency_table$Freq,names.arg = Frequency_table$qualitative_variable_name,las=2)

When using basic plot functions in R, the following inputs are very valuable and consistent across all plot functions:

In the following barplot command, these inputs are used to make the bar graph more visually appealing and straight-forward.

barplot(Table1_Freq$Freq,names.arg=Table1_Freq$Location,main="Types of Rehabilitation",xlab="Body Part",ylab="Frequency",col='#6897bb',las=2)

To create a relative frequency bar graph from the summarized data, use the same command except use the saved relative frequency distribution.

barplot(Table1_RelFreq$Freq,names.arg=Table1_RelFreq$Location,main="Types of Rehabilitation",xlab="Body Part",ylab="Relative Frequency",col='#6897bb',las=2)

Bar Graphs from Raw Data

Using Base r

Table1 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter2/Table1.csv")

First, we draw a frequency bar graph.

bargraph(~Location,data=Table1,main="Types of Rehabilitation",ylab="Frequency",xlab="Body Part",col='#3832a8')

Now, draw a relative frequency bar graph.

bargraph(~Location,data=Table1,main="Types of Rehabilitation",ylab="Relative Frequency",xlab="Body Part",col='#3832a8',type="proportion")