VIS-2129-F2020 / jtang-vis

1 stars 0 forks source link

Assignment03 Issues #4

Closed jtanggsd closed 4 years ago

jtanggsd commented 4 years ago

Hi,

I'm not sure if I'm supposed to put my code here, but I am referring to this: https://github.com/VIS-2129-F2020/jtang-vis/blob/master/assignment03_jt.Rmd

I already submitted my assignment, so really I would just like to know what I am doing wrong at some point. Thank you!

c-voulgaris commented 4 years ago

Your repo doesn't include the geojson file for plazas, so I can't run any of the code that uses that - for review purposes, I've commented out the code that uses the plaza locations.

On your first bullet point - what's happening is that your wifi layer has about 169 points that are duplicates of other points (they're the exact same location). So when you pull them out and add them back in, they get added back in multiple times.

Add the following line someplace before line 103 to delete duplicate locations.

wifi <- st_difference(wifi)

Also, some of the names of your wifi locations are NA even before the join, so use a different variable to identify the ones that are near fountatains. city.y works, so you can replace line 108 with:

  mutate(near_fountains = !is.na(city.y))

Based on the revised calculation, update your caption in line 144 to:

       caption = "Of 3,350 Wifi hotspots in NYC, 2,384 (76%) are within 0.25 mi of a drinking fountain.") +

I'd prefer you had the caption pull the numbers from a variable like in the tutorial example, so that if you update the code, you don't have to remember to recheck the calculation and update the caption manually. But I won't insist on that.

Similar thing for the fountains. Add this line somewhere before line 166:

fountains <- st_difference(fountains)

Then update line 205 to:

       caption = "Of 3,116 drinking fountains in NYC, 1,816 (58.3%) are within 0.25 mi of a Wifi hotspot.") +

On the Q3 question, st_nn doesn't like feet when the projection calls them US survey feet. Try switching to a coordinate system that's in meters. You can always convert the units back to feet. Rewrite that code chunk as follows:

CRS_meters <- "+proj=tmerc +lat_0=38.83333333333334 +lon_0=-74.5 +k=0.9999 +x_0=150000 +y_0=0 +ellps=GRS80 +units=m +no_defs"

wifi <- wifi %>% 
  st_transform(CRS_meters) 

fountains <- fountains %>%
  st_transform(CRS_meters)

wifi <- wifi %>%
  mutate(fountain_dist_m = as.numeric(st_nn(wifi, fountains,
                               returnDist = TRUE)$dist)) %>%
  mutate(fountain_dist_ft = fountain_dist_m * 3.28084) %>%
  st_transform(nyc_epsg2263)

fountains <- fountains %>%
  st_transform(nyc_epsg2263)

paste("The average distance from a wifi hotspot to the closest fountain is",
      prettyNum(mean(wifi$fountain_dist_ft), digits = 0), "ft.")

On your last bullet point, you need to set the extents in the unit that your coordinate system is in (state plane feet). If you want to set your coordinate limits in lat/lon coordinates, set the crs (just within that function) to one that uses lat/lon. So instead of adding coord_sf(crs = nyc_epsg2263, xlim = c(-74, -73.8), ylim = c(40.6, 40.9)),

add coord_sf(crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", xlim = c(-74, -73.8), ylim = c(40.6, 40.9))