Notes

Libraries

library(EdSurvey)
## Loading required package: car
## Loading required package: carData
## Loading required package: lfactors
## lfactors v1.0.4
## Loading required package: Dire
## Dire v2.1.0
## EdSurvey v3.0.1
## 
## Attaching package: 'EdSurvey'
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
require(ggplot2)
## Loading required package: ggplot2

Data

sdf <- readNAEP(system.file("extdata/data", "M36NT2PM.dat", package = "NAEPprimer"))

Curiously, “sdf” is not a data object. So far no data have been read in. Odd. Instead “sdf” merely points to a the data. Not sure what that is about.

“GET DATA”. I guess the variable is b017451 ,and we want the original weight(unweighted)

Four variables: dsex = Gender sdracem - Race/Ethnicity pared = Parental Education level b017451 = talk about school at home the Weights are Origintt and 62 replicates= srwt01 to srwt62

gddat <- getData(sdf, c('dsex', 'sdracem', 'pared', 'b017451',
'composite', 'geometry', 'origwt'),
omittedLevels = FALSE)

To see the default weight of a df

showWeights(sdf)
## There is 1 full sample weight in this edsurvey.data.frame:
##   'origwt' with 62 JK replicate weights (the default).

Figure 1 shows a bar chart with counts of the variable b017451 in each category.

bar1 <- ggplot(data=gddat, aes(x=b017451)) +
geom_bar() +
coord_flip() +
labs(title = "Talking About School")
bar1

Note above we have the Gender varaible we do not call it .

# R code for generating Figure 2
bar2 <- ggplot(data=gddat, aes(x=b017451, fill=dsex)) +
geom_bar() +
coord_flip() +
labs(title = "Who Talks More About School?")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
theme(panel.background = element_rect(fill = '#8494FF', color = 'gold'))
bar2

Colr the bars

I ws looking for the ggplot color codes for Hofstra’s Blue&Gold

bar2 <- ggplot(data=gddat, aes(x=b017451, fill=dsex)) +
geom_bar() +
coord_flip() +
labs(title = "Who Talks More About School?")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
theme(panel.background = element_rect(fill = 'cadetblue1', color = 'gold'))+
  scale_fill_manual(values=c("#00A9FF",
                             "deeppink"))
  
bar2

I am kind of in the Tufte school, every pixels has to fight to get in.

bar2 <- ggplot(data=gddat, aes(x=b017451, fill=dsex)) +
geom_bar() +
coord_flip() +
labs(title = "Who Talks More About School?")+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
theme(panel.background = element_rect(fill = 'white', color = 'gold'))+
  scale_fill_manual(values=c("#00A9FF",
                             "deeppink"))
  
bar2

Histograms

# R code for generating Figure 4
hist2 <- ggplot(gddat, aes(x=mrpcm1, fill = dsex)) +
geom_histogram(position="identity", alpha = 0.7) +
labs(title = "Figure 4")+
theme(panel.background = element_rect(fill = 'white', color = 'gold'))+
scale_fill_manual(values=c("#00A9FF",
                             "deeppink"))+
labs(title = "Who Talks More About School?")
hist2
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Box Plots faceted on gender

box1 <- ggplot(gddat, aes(x=sdracem, y=mrpcm1 , fill = dsex)) +
geom_boxplot() +
stat_summary(fun.y=mean, geom="point", shape=23, size=4) +
coord_flip() +
facet_grid(dsex ~ .) +
theme(panel.background = element_rect(fill = 'white', color = 'gold'))+
labs(title = "Plot About Talk By Race & Gender")
## Warning: `fun.y` is deprecated. Use `fun` instead.
box1