# A tibble: 6 × 11
City Address.x Zip Institution Primary Affiliation.…¹ Position.x State
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 Northampt… 341 Pros… 1060 Amherst Co… 4-year College Faculty MA
2 <NA> <NA> <NA> Arizona St… 4-year College Student AZ
3 <NA> <NA> <NA> Arizona St… Research Institution Faculty AZ
4 <NA> <NA> <NA> Bucknell U… 4-year College Faculty PA
5 <NA> <NA> <NA> Bucknell U… 4-year College Other PA
6 Los Osos PO Box 7… 9341… Cal Poly a… 4-year College Faculty CA
# ℹ abbreviated name: ¹`Primary Affiliation.x`
# ℹ 4 more variables: `Work ZIP/Postal Code` <chr>, region <chr>, lat <dbl>,
# lon <dbl>
USCOTS
Useful Models
geocode using geoapify
https://www.geoapify.com/tools/geocoding-online/
Add regions and arrow end points
#registra <- registr |>
# filter(Institution != "Other?(not?a?CAUSE?institutional?member")|>
#rename(count = n) |>
#mutate(
# region = case_when(
# State %in% c("CT", "ME", "MA", "NH", "RI", "VT", "NJ", "NY", "PA") ~ "Northeast",
# State %in% c("IL", "IN", "MI", "OH", "WI", "IA", "KS", "MN", "NE", "ND", "SD") ~ "Midwest",
#State %in% c("DE", "FL", "GA", "MD", "NC", "SC", "VA", "DC", "WV", "AL", "KY", "MI", "TN", "AR", "LA", "OK", "TX", "PR") ~ "South",
#State %in% c("AZ", "MO", "CO", "ID", "MT", "NV", "NM", "UT", "WY", "AK", "CA", "HI", "OR", "WA") ~ "West",
#FALSE ~ "Other")
#)|>
#filter(!is.na(region))cause1 <- cause |>
filter(!is.na(region))Jitter the points
#cause1$lat_jitter <- jitter(cause1$lat, factor = 0.00001) # Adjust factor.
#cause1$lon_jitter <- jitter(cause1$lon, factor = 0.00001)Create a color palette for the regions
library(wesanderson) wes_palette(“FantasticFox1”)
pal <- colorFactor(palette = c("#7538a1","#db8b12","#169bc7", "#c4313d"),
domain = cause1$region)Set the default lat/long for the map
lat <-38.7946
lon <- -97.5348
popup = paste0(
"<b>Institution:</b> ", cause1$Institution, "<br>",
"<b>City:</b> ", cause1$City, "<br>",
"<b>State:</b> ", cause1$State, "<br>")m <- leaflet(data = cause1) |>
addProviderTiles(providers$Thunderforest.Landscape) |>
setView(lng = lon, lat = lat, zoom = 3.5) |>
addTiles() |>
addMarkers(
lng = -93.6465,
lat = 42.0267,
label = "ISU")|>
addCircles(
color = pal(cause1$region),
popup = popup,
radius = 1500,
opacity = 0.6)|>
addLegend("bottomright", pal = pal, values = cause1$region,
title = "Region", opacity = 1) Assuming "lon" and "lat" are longitude and latitude, respectively
mcalculate distance from Iowa State U
library(sf)Warning: package 'sf' was built under R version 4.5.1
Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
df_sf <- st_as_sf(cause1, coords = c("lat", "lon"), crs = 4326)
# 4326 is WGS 84, a common CRS for geographic coordinates
df_sf <- st_set_crs(df_sf, 4326)Use Haversine formula
library(geosphere)Warning: package 'geosphere' was built under R version 4.5.1
ames_lon <- -93.616669
ames_lat <- 42.034737
cause1$distance <- distHaversine(
p1 = cbind(cause1$lon, cause1$lat),
p2 = c(ames_lon, ames_lat)
)cause2 <- cause1 |>
filter(!is.na(distance)) |>
mutate(distance_miles = distance/1609.344)Distance Stats
dist <- cause2 |>
arrange(desc(distance_miles))
dist# A tibble: 231 × 13
City Address.x Zip Institution Primary Affiliation.…¹ Position.x State
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 <NA> <NA> <NA> North Caro… Research Institution Faculty NC
2 <NA> <NA> <NA> The Ohio S… Research Institution Student OH
3 <NA> <NA> <NA> The Ohio S… Research Institution Faculty OH
4 <NA> <NA> <NA> The Ohio S… Research Institution Faculty OH
5 <NA> <NA> <NA> University… Research Institution Faculty GA
6 <NA> <NA> <NA> University… Research Institution Student GA
7 <NA> <NA> <NA> University… 4-year College Faculty GA
8 <NA> <NA> <NA> University… 4-year College Faculty GA
9 <NA> <NA> <NA> University… Research Institution Faculty GA
10 San Fran… One Mont… 94104 Other (not… Exhibitor Other CA
# ℹ 221 more rows
# ℹ abbreviated name: ¹`Primary Affiliation.x`
# ℹ 6 more variables: `Work ZIP/Postal Code` <chr>, region <chr>, lat <dbl>,
# lon <dbl>, distance <dbl>, distance_miles <dbl>
Proportion of Faculty to students for each Primary Affiliation
library(knitr)
library(kableExtra)
Attaching package: 'kableExtra'
The following object is masked from 'package:dplyr':
group_rows
cause_table <- cause1 |>
filter(`Primary Affiliation.x` != "Other")|>
mutate(type = case_when(`Primary Affiliation.x` %in% c("Research Institution", "4-year College") ~ "four-year",
`Primary Affiliation.x` == "2-year College" ~ "two-year",
TRUE ~ "Other"))|>
select(type, Position.x) |>
table()
kbl(cause_table, caption = "Two-Way Table") |>
kable_styling() |>
row_spec(row = 0, color = "#C41E3A")| Faculty | Other | Student | |
|---|---|---|---|
| four-year | 183 | 5 | 30 |
| Other | 0 | 4 | 0 |
| two-year | 7 | 0 | 0 |
table of states
state_table <- cause1 |>
group_by(State) |>
tally() |>
arrange(desc(n))
kbl(state_table, caption = "Two-Way Table") |>
kable_styling() |>
row_spec(row = 0, color = "#C41E3A")|>
column_spec(1, width = "0.5in")| State | n |
|---|---|
| IA | 33 |
| CA | 28 |
| MN | 28 |
| MI | 23 |
| NY | 19 |
| PA | 17 |
| IL | 15 |
| NC | 15 |
| OH | 9 |
| MO | 7 |
| GA | 5 |
| KY | 4 |
| OR | 4 |
| MA | 3 |
| AZ | 2 |
| FL | 2 |
| MD | 2 |
| MT | 2 |
| NJ | 2 |
| WI | 2 |
| CO | 1 |
| IN | 1 |
| KS | 1 |
| NE | 1 |
| NM | 1 |
| TX | 1 |
| VA | 1 |
| VT | 1 |
| WA | 1 |