How to draw bar plot and pie chart of a frequency distribution from a given data:
Example:
> age=scan() [enter age of some woman by variable age]
1: 20
2: 24
3: 19
4: 24
5: 18
6: 19
7: 24
8: 22
9: 23
10: 19
11: 19
12: 24
13: 2
14: 21
15: 22
16: 23
17: 24
18: 21
19: 25
20: 23
[enter two times to stop entering process]
Read 20 items
> freq=table(age)
> cumfreq=cumsum(freq)
> cbind(freq, cumfreq)
freq cumfreq
2 1 1
18 1 2
19 4 6
20 1 7
21 2 9
22 2 11
23 3 14
24 5 19
25 1 20
> color=c("red", "green", "blue") [to define color]
> barplot(freq,col=color) [to draw bar plot with defined colors]
> pie(freq, col=color) [to draw pie chart with defined colors]
Example:
> age=scan() [enter age of some woman by variable age]
1: 20
2: 24
3: 19
4: 24
5: 18
6: 19
7: 24
8: 22
9: 23
10: 19
11: 19
12: 24
13: 2
14: 21
15: 22
16: 23
17: 24
18: 21
19: 25
20: 23
[enter two times to stop entering process]
Read 20 items
> freq=table(age)
> cumfreq=cumsum(freq)
> cbind(freq, cumfreq)
freq cumfreq
2 1 1
18 1 2
19 4 6
20 1 7
21 2 9
22 2 11
23 3 14
24 5 19
25 1 20
> color=c("red", "green", "blue") [to define color]
> barplot(freq,col=color) [to draw bar plot with defined colors]
> pie(freq, col=color) [to draw pie chart with defined colors]
No comments:
Post a Comment