1. LON-CAPA Logo
  2. Help
  3. Log In
 

Browsing resource, all submissions are temporary.


Plotting Stat 100 Survey Data

The csv file for the Stat 100 Survey 2 data in Fall 2013 can be downloaded here. Download the file and load it to R using the command

survey <- read.csv("stat100_2013fall_survey02.csv")

Here is a description of the data in each column. Explore the data.

The histogram() function in the lattics graphics system can also be applied to categorical data (i.e. factor variables). The result is a barplot. Try the following commands:

library(lattice)
histogram(~religion, data=survey)

a. Use the histogram() function to make split plots of 'religion' for each ethnicity. You will need to increase the width of the graph in order to separate the labels. In R Studio, this can be done by clicking the "Zoom" button on the Plot panel. A separete window for the plot will pop up and you can maximize the window. From the plots, what is the most popular religion for the ethnic group "Asian"?






 Tries [_1]

b. Which ethnic groups have students believing in Hinduism? (Select all that apply)
White
Hispanic/Latino
Black/African American
Asian
Mixed/Other

 Tries [_1]

c. Which group of students has the highest percentage of having same sex experience?








 Tries [_1]

d. Consider the following two commands plotting number of sex partners versus number of relationship:

plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=gender, data=survey)

plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=1:2, data=survey)

What is the difference between these two commands?





 Tries [_1]

e. Continuing with the question in (d). suppose I want to plot males in green and females in red. Which of the following commands produce the desired plot? (Select all that apply)
cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[gender], data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-as.integer(gender), data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=gender+1, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=3:2, data=survey)
cols <- c("red","green"); plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=cols[as.integer(gender)], data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=2:3, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=as.integer(gender)+1, data=survey)
plot(jitter(sexPartners) ~ jitter(relationships), pch=16, col=4-gender, data=survey)
None of the above

 Tries [_1]