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
sdf <- readNAEP(system.file("extdata/data", "M36NT2PM.dat", package = "NAEPprimer"))
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)
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
# 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
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
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
# 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`.
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