In this exercise we weill use the Add Health data to try some graphing. first we will load the add health data.

This first part loads the programs we need.

First let’s make a histogram of age. This show the number at each age. The age variable is S3

addhealth %>% ggvis(~S3) %>% layer_histograms()
## Guessing width = 0.2 # range / 35

You can add labels

Put these next %>% add_axis(“x”, title = “Age”) %>% add_axis(“y”, title = “Count”)

 addhealth %>% ggvis(~S3) %>% layer_histograms()  %>% add_axis("x", title = "Age") %>% 
  add_axis("y", title = "Count") 
## Guessing width = 0.2 # range / 35

## Add a little space between the labels and the axes

 addhealth %>% ggvis(~S3) %>% layer_histograms()  %>%
   add_axis("x", title = "Age", title_offset="50") %>% 
   add_axis("y", title = "Count", title_offset="50") 
## Guessing width = 0.2 # range / 35

addhealth %>% ggvis(~S3) %>% layer_histograms()  
## Guessing width = 0.2 # range / 35

You can change the colors

stroke := (This is the outline. Put the name of a color or number of a color in quotation marks) fill := (This is what goes in the middle)

 addhealth %>% ggvis(~S3) %>% layer_histograms(fill := "pink", stroke="blue")
## Guessing width = 0.2 # range / 35

You can add options inside the layer parentheses

width (changes how wide the bars are, based on the values of your variable) center (usually 0 or .5)

 addhealth %>% ggvis(~S3) %>% layer_histograms(width=5, center = 0)

 addhealth %>% ggvis(~S3) %>% layer_histograms(width=1, center = .5)

You can combine these together.

(You can break up the lines, makes sure to put the %>% at the end of each line.)

addhealth %>% 
      ggvis(~S3) %>% 
      layer_histograms(fill := "pink", stroke="blue", width=1, center = .5)    %>%
      add_axis("x", title = "Age") %>% 
      add_axis("y", title = "Count") 

Below make 5 different versions of the histogram for age.

Which do you think is the best one? Why?

Type your answer below:

Look at the histogram you picked. What does the distribution of age look like in your histogram?

Type answer below:

Make a new histogram

The variable name for grade is S3. Make a histogram for grade.

Look at your histogram. What does the distribution of grade look like in your histogram?

Type answer below: