# Graphics problems
#------------------
# Load the classroom data you saved in the Reading data exercises,
# or just load() it from our website.
# Plot 1
#-------
# Create a histogram of the mathkind (mathematics score in
# kindergarten) variable. Add an xlab= to better explain
# what the graph is about.
# Plot 2
#-------
# Create an empirical density plot of mathkind.
# Plot 3
#-------
# Create an empirical density plot of mathkind by sex using
# the optional argument groups = sex. It is probably a good
# idea to suppress the points in the "rug", with the plot.points=FALSE
# option. Remember to use auto.key so you can tell which curve is which.
# Plot(s) 4
#-------
# In xyplot(), the default it to plot points. You can plot an
# empirical "smoother" instead, with option type="smooth". You
# can overlay to "types" that use the same data with
# type=c("p", "smooth").
# Create a scatter-plot of the mathgain versus the kindergarten score.
# Add a smoother curve and a ylab (y axis label).
# Repeat this plot using type "r"
# instead of "smooth" to add a reference (or "regression")
# line.
# Plot 5
#-------
# Find the correlation between mathkind and mathgain. The negative
# result is not surprising because mathgain is the grade 1 score minus
# the kindergarten score. Create a new variable math1 which is
# the sum of mathkind and mathgain.
# Plot math1 versus mathkind. Try using the
# optional argument aspect="iso" to ensure that a
# unit change on the x axis corresponds to a unit change on the y axis.
# Plot 6
#-------
# Create a multi-panel scatterplot of math1 versus
# mathkind with separate panels for males and females.
# Plot 7
#-------
# Create a multi-panel scatterplot of math1 versus
# mathkind classified according to sex and minority.
# Plot 8
#-------
# Consider only the students in school 11. xyplot has a subset option
# that allows you to specify, for instance, subset=(schoolid==11).
# Show that the study includes students from nine different classrooms
# in that school.
# Create a dot-plot of the mathgain by classroom for students
# in school 11 only. Label the x and y axis.
# Plot 9
#-------
# Repeat the plot, joining the classroom averages by overlaying
# type "a".
# Plot 10
#--------
# Finally, you can reorder the classrooms with the
# reorder() function (which relevels a factor).
# reorder(classid, mathgain) will
# do the trick (the default function applied to mathgain is
# the mean() ).
# Redo the plot reordering the classrooms according
# to increasing mean gain and joining the classroom averages.
# Bonus plots
#------------
# You can reorder() the levels of a factor by other functions. How
# would the previous example change if we reordered by max(mathgain)?
# by mean(ses)?