> margin.table(Titanic) # gives total count if index is not provided > margin.table(Titanic,4) # count according to survival > margin.table(Titanic,1) # count according to class This function sums up the table entries according to the given index. In this case we can use the margin.table() function. Suppose we wanted to bar plot the count of males and females. We can see that this data has 4 dimensions, class, sex, age and survival. This data set provides information on the fate of passengers on the fatal maiden voyage of the ocean liner ‘Titanic’, summarized according to economic status (class), sex, age and survival.-R documentation. For example, let us take the built-in Titanic dataset. Sometimes the data is in the form of a contingency table. Note below, that we define the argument density to shade the bars. Now plotting this data will give our required bar plot. Let us suppose, we have a vector of maximum temperatures (in degree Celsius) for seven days as follows. If we supply a vector, the plot will have bars with their heights equal to the elements in the vector. We can supply a vector or matrix to this function. Bar plots can be created in R using the barplot() function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |