Use the bargraph command if the value of a categorical variable is given for every observation.
bargraph(~feed,data=chickwts)
Use the barchart command to create a bar graph for a data set where the frequencies of a catagorical variable are given.
gps<-read.file("/home/emesekennedy/Data/Ch1/gps.txt")
## Reading data with read.table()
barchart(MarketShare~Company,data=gps)
barchart(Company~MarketShare,data=gps)
tree1<-subset(Orange, Tree==1)
xyplot(circumference~age,data=tree1)
xyplot(circumference~age,data=tree1,type="l")
xyplot(circumference~age,data=tree1, type="b")
time24<-read.file("/home/emesekennedy/Data/Ch1/timetostart24.txt")
## Reading data with read.table()
histogram(~TimeToStart,data=time24,type="count")
mean(~TimeToStart,data=time24)
## [1] 37.375
median(~TimeToStart,data=time24)
## [1] 36.5
Same data set with an outlier
time25<-read.file("/home/emesekennedy/Data/Ch1/timetostart25.txt")
## Reading data with read.table()
histogram(~TimeToStart,data=time25,type="count")
mean(~TimeToStart,data=time25)
## [1] 63.64
median(~TimeToStart,data=time25)
## [1] 40
Create data set with grades
grades<-c(80, 73, 95,98,100,77,72,60,82)
histogram(grades,type="count",width=10)
mean(grades)
## [1] 81.88889
median(grades)
## [1] 80
favstats(grades)
## min Q1 median Q3 max mean sd n missing
## 60 73 80 95 100 81.88889 13.42986 9 0
Save the result as a variable named stats
stats<-favstats(grades)
Calculate the interquartile range
IQR<-stats[1,4]-stats[1,2]
Find cutoff values for suspected outliers
stats[1,4]+1.5*IQR
## [1] 128
stats[1,2]-1.5*IQR
## [1] 40
Create a boxplot
bwplot(grades)
Five number summary and boxplot for the time24 data:
favstats(~TimeToStart, data=time24)
## min Q1 median Q3 max mean sd n missing
## 4 23 36.5 46.25 77 37.375 18.57491 24 0
bwplot(~TimeToStart,data=time24)
Five number summary and boxplot for the time25 data (with the outlier):
favstats(~TimeToStart, data=time25)
## min Q1 median Q3 max mean sd n missing
## 4 23 40 47 694 63.64 132.5779 25 0
bwplot(~TimeToStart,data=time25)
Note: R Studio recognized the outlier and created a modified boxplot