Graphics Reference
In-Depth Information
1900
5
-
14
16966
1900
15
-
24
14951
1900
25
-
34
12161
1900
35
-
44
9273
1900
45
-
54
6437
1900
55
-
64
4026
1900
>
64
3099
1901
<
5
9336
1901
5
-
14
17158
...
We'll use
ddply()
to split it into separate data frames for each value of
Year
, then apply the
transform()
function to each piece and calculate the
Percent
for each piece. Then
ddply()
puts all the data frames back together:
uspopage_prop
<-
ddply(uspopage,
"Year"
, transform,
Percent
=
Thousands
/
sum(Thousands)
*
100
)
Year AgeGroup Thousands Percent
1900
<
5
9181 12.065340
1900
5
-
14
16966 22.296107
1900
15
-
24
14951 19.648067
1900
25
-
34
12161 15.981549
1900
35
-
44
9273 12.186243
1900
45
-
54
6437 8.459274
1900
55
-
64
4026 5.290825
1900
>
64
3099 4.072594
1901
<
5
9336 12.033409
1901
5
-
14
17158 22.115385
...
See Also
For more on summarizing data by groups, see
Summarizing Data by Groups
.
Adding a Confidence Region
Problem
You want to add a confidence region to a graph.
Solution
Use
geom_ribbon()
and map values to
ymin
and
ymax
.