5.2 Category 3 Variable 2: Percentage of People with a Doctorate Degree

5.2.1 Map of % of People with a Doctorate Degree in the United States

my.bins <- c(0, 1, 2, 5, 10, 20)
pal <- colorBin("OrRd", metadataGIS$perc_doc, bins = my.bins, reverse=FALSE)

leaflet(metadataGIS, options = leafletOptions(crsClass = "L.CRS.EPSG3857"), width="100%") %>%
  addPolygons(weight = 0.5, color = "gray", opacity = 0.7,
    fillColor = ~pal(perc_doc), fillOpacity = 1, smoothFactor = 0.5,
    label = popupPlus("% PhD", metadataGIS$perc_doc, "number"),
    labelOptions = labelOptions(direction = "auto")) %>%
    addPolygons(data = stateGIS,fill = FALSE,color="black",weight = 1) %>%
    addLegend(pal = pal,values = ~metadataGIS$perc_doc, opacity = 0.7, title = "% PhD",position = "bottomright")

5.2.2 Scatterplot of % of People with a Doctorate Degree and % of GOP Votes in a county

ggplot(metadata, aes(perc_doc, pctGOP*100), color = "#666666", alpha = 0.2) +
  geom_point(color = "#AA4371", alpha = 0.2) +
  geom_histogram(aes(perc_doc, ..count../50), alpha = 0.2, color = "#33A02B", fill ="#B2DF8A" ) +
  geom_smooth(method = "lm", color = "#1F78B4", fill = "#A6CEE3") +
  geom_smooth(method = "loess", color = "red") +
  labs(title="Regression line percentage of people with a PhD on vote for GOP", x= "People with a PhD(%)", y= "Vote for GOP(%)", caption = "Histogram of the variable at the bottom, not scaled to the y axis. \n For the purpose of visualization, one outlier (Los Alamos, NM) was ommited from the plot.")+
  ylim(0, 100) +
# xlim() is being used to remove the outlier and hence improve the visualization of the data
  xlim(0, 10) +
  theme_bw()

5.2.3 Summary Table for Regression of % of People with PhD

model2.1 <- lm(pctGOP~perc_doc,data=metadata)
stargazer(model2.1, 
          type = "html", 
          report=('vc*p'),
          keep.stat = c("n","rsq","adj.rsq"), 
          notes = "<em>&#42;p&lt;0.1;&#42;&#42;p&lt;0.05;&#42;&#42;&#42;p&lt;0.01</em>", 
          notes.append = FALSE)
Dependent variable:
pctGOP
perc_doc -0.080***
p = 0.000
Constant 0.729***
p = 0.000
Observations 3,108
R2 0.206
Adjusted R2 0.206
Note: *p<0.1;**p<0.05;***p<0.01