cars=c(30,50, 20)
names(cars)=c("Blue Car Sales","Red Car Sales", "Green Car Sales")
barplot(cars, main="Car Sales by Color", ylab="Frequency", col=c("blue","red", "green"))
mylab=paste(names(cars),"\n", cars, sep="")
pie(cars, main="Car Sales by Color", ylab="Frequency", labels=mylab,col=c("blue","red", "green"))
par(mfrow=c(3,1)) #3 x 1 graphing space
myhist=hist(na.omit(airquality$Ozone), plot=FALSE) #hist ogram
names(myhist$counts)=paste("[",myhist$breaks[1:9],", ",myhist$breaks[2:10],")", sep="") #making the names for the graph
barplot(myhist$counts, space=0, main="Histogram, Ozone Levels in NY, May-Sep 1973", xlab="Ozone, ppb", ylab="Counts", col="red")
barplot(myhist$counts/sum(myhist$counts), col="yellow",space=0, main="Rel. Freq. Histogram, Ozone Levels in NY, May-Sep 1973", xlab="Ozone, ppb", ylab="Proportion")
mycol <- rgb(0, 0, 255, max = 255, alpha = 75, names = "blue50")
polygon(c(0,seq(.5,8.5, by=1),8.5),c(0,myhist$density*20,0), col=mycol)
boxplot(na.omit(airquality$Ozone),main="Ozone example", horizontal=TRUE)
#Density Plot and CDF Plot
mydensity=density(na.omit(airquality$Ozone))
mydensity$y=mydensity$y*20
plot(mydensity,main="Example Density Plot, Ozone Data",col="red",xlab="Ozone, ppb",ylab="Proportion")
plot(ecdf(na.omit(airquality$Ozone)),main="Cumulative Distribution Function, Ozone Example", xlab="f(x)=Ozone, ppb", ylab="F(x)")
j=JohnsonJohnson
x1=mean(j) # mean
x2=median(j) # median
x3=max(j)-min(j) #range
x4=sum(abs(j-mean(j))/length(j)) #mean abs dev
x5=mad(j) #median abs dev
x6=var(j) #variance
x7=sd(j) #sd
results = round(c(x1, x2, x3, x4, x5, x6, x7),3)
names(results)=c("Mean", "Median", "Range", "Mn Abs Dev", "Md Abs Dev", "Var", "Sd")
results
## Mean Median Range Mn Abs Dev Md Abs Dev Var
## 4.800 3.510 15.760 3.554 3.840 18.576
## Sd
## 4.310
require(psych)
## Loading required package: psych
describe(j)
## vars n mean sd median trimmed mad min max range skew kurtosis
## X1 1 84 4.8 4.31 3.51 4.2 3.84 0.44 16.2 15.76 0.99 -0.05
## se
## X1 0.47
freq=c(6,18,11, 11, 3, 1)
mids=c(25, 35, 45, 55, 65, 75)
mymean=sum(freq*mids)/sum(freq)
mymean
## [1] 43
par(mfrow=(c(3,1)))
hist(JohnsonJohnson,main="J&J Example")
boxplot(JohnsonJohnson,main="J&J Example", horizontal=TRUE)
quarter=factor(rep(seq(1:4),21))
boxplot(JohnsonJohnson~quarter, notch=T, col=seq(1:4), main="J&J by Quarter")
## Warning in bxp(list(stats = structure(c(0.61, 1.16, 2.79, 6.93, 14.04,
## 0.63, : some notches went outside hinges ('box'): maybe set notch=FALSE
quantile(j, c(0,.25, .5, .75, 1))
## 0% 25% 50% 75% 100%
## 0.4400 1.2475 3.5100 7.1325 16.2000
fivenum(j)
## [1] 0.440 1.245 3.510 7.335 16.200