To get the data set click this link : Friends Data from Carnegie Mellon University. data will be Data will be downloaded on your computer. Double click the downloaded file. A new session of R will start and data will be loaded in a variable named: friends.
To take a look at the data, type:
> friends
Create a table:
> t <- table(friends)
see the table:
> t
friends
No difference Opposite sex Same sex
602 434 164
> barplot(t)
Output:
> barplot(t, horiz=T)
Try
> barplot(t, horiz=T, main="Friends Distribution", ylab="Make Friends With", col="darkblue")
For more examples, check: http://www.statmethods.net/graphs/bar.html
Pie Chart
------------
> pie(t)
To take a look at the data, type:
> friends
Create a table:
> t <- table(friends)
see the table:
> t
friends
No difference Opposite sex Same sex
602 434 164
> barplot(t)
Output:
> barplot(t, horiz=T)
Try
> barplot(t, horiz=T, main="Friends Distribution", ylab="Make Friends With", col="darkblue")
For more examples, check: http://www.statmethods.net/graphs/bar.html
Pie Chart
------------
> pie(t)
To create 3D pie chart:
> install.packages("plotrix")
>library(plotrix)
>pie3D(t, explode=.1)



No comments:
Post a Comment