x=matrix(c(25,20,55, 20,35,15, 5,20,5),nrow=3)
x
## [,1] [,2] [,3]
## [1,] 25 20 5
## [2,] 20 35 20
## [3,] 55 15 5
rownames(x)=c("21-40","41-60","Over 60")
x
## [,1] [,2] [,3]
## 21-40 25 20 5
## 41-60 20 35 20
## Over 60 55 15 5
colnames(x)=c("For","Against","No Opinion")
x
## For Against No Opinion
## 21-40 25 20 5
## 41-60 20 35 20
## Over 60 55 15 5
barplot(x,beside=TRUE,
legend.text=TRUE,
xlab="Voter Outcomes",
ylab="Age",
main="Relation Between Age and Support for Higher Min. Wage",
col=rainbow(3))
x.margins=addmargins(x)
print(x.margins)
## For Against No Opinion Sum
## 21-40 25 20 5 50
## 41-60 20 35 20 75
## Over 60 55 15 5 75
## Sum 100 70 30 200
x.cond.prob=prop.table(x,2)
print(x.cond.prob)
## For Against No Opinion
## 21-40 0.25 0.2857 0.1667
## 41-60 0.20 0.5000 0.6667
## Over 60 0.55 0.2143 0.1667
barplot(x.cond.prob,
beside=TRUE,
legend.text=TRUE,
xlab="Voter Outcomes",
ylab="% of Voters Age Per Option",
main="Relation Between Age and Min. Wage Increase Opinions",
col=rainbow(3))
I displayed the relationship between the age of voters and their support for minimum wage increases with a bar plot.The code that was used in the first bar plot I created is information about the number of voters of different age groups. The second barplot information was caculated in “R” from the original data to show the percenatges of voter’s age per option. I learned that the titles for colum names doesn’t always show in my console window.