Introduction to Statistics (MAT/SST 115.03 2008S)
Primary: [Front Door] [Syllabus] [Current Outline] [R] - [Academic Honesty] [Instructions]
Groupings: [Applets] [Assignments] [Data] [Examples] [Handouts] [Labs] [Outlines] [Projects] [Readings] [Solutions]
External Links: [R Front Door] [SamR's Front Door]
6-1.a asks you to compute some proportions. You can certainly ask R to do those computations.
EnvSpend = c(398/646, 198/646, 50/646)
6-1.b asks you to construct a bar graph. Here's a straightforward approach.
barplot(c(398,198,50),
main="Opinions About Federal Envt Spending",
names.arg = c("Too Little", "Just Right", "Too Much")
)
If we care abaout proportions, rather than absolute numbers, we can use the vector we just created.
barplot(EnvSpend,
main="Opinions About Federal Envt Spending",
names.arg = c("Too Little", "Just Right", "Too Much")
)
This exercise asks you to make a stacked bar graph. You should read notes on stacked bar graphs to see how to make one in R.
If you're impatient, here are some basic instructions.
EnvironmentSpending = data.frame(
Liberal = c(.819, .174, .007),
Moderate = c(.619, .314, .067),
Conservative = c(.479, .385, .136)
)
rownames(EnvironmentSpending) = c("Too Little", "About Right", "Too Much")
barplot(as.matrix(EnvironmentSpending),
main="Political Perspectives on Environment Spending",
col=c("green", "grey", "red")
)
To add the legend (which R likes to put in a stupid place), replace the last command with
barplot(as.matrix(EnvironmentSpending),
main="Political Perspectives on Environment Spending",
legend=rownames(EnvironmentSpending),
col=c("green", "grey", "red")
)
Primary: [Front Door] [Syllabus] [Current Outline] [R] - [Academic Honesty] [Instructions]
Groupings: [Applets] [Assignments] [Data] [Examples] [Handouts] [Labs] [Outlines] [Projects] [Readings] [Solutions]
External Links: [R Front Door] [SamR's Front Door]
Copyright (c) 2007-8 Samuel A. Rebelsky.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.