# R notes for Activity 6-1

## 6-1.a

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

6-1.b asks you to construct a bar graph. Here's a straightforward approach.

```barplot(c(398,198,50),
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,
names.arg = c("Too Little", "Just Right", "Too Much")
)
```

## 6-1.i

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")
)
```

Samuel A. Rebelsky, rebelsky@grinnell.edu

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.