uwescience / WaterReuseDSSG2024

Drivers-Based Water Reuse Potential project for DSSG summer 2024
Apache License 2.0
1 stars 1 forks source link

feat: Having trouble plotting *points* representing facilities #22

Closed voglerdaniel closed 2 days ago

voglerdaniel commented 5 days ago

I am curious whether there is a way to plot color-coded points representing facilities using urbnmapr rather than color-coding counties or census tracts.

The CWNS dataset reports total wastewater flow for each facility, along with its latitude and longitude. I'd like to use this physical location data to plot a point for each facility and color-code it based on the amount of total flow to create a heatmap. However, I'd like to overlay these points over the urbnmapr states shapefile, so that we can tell in which state each point is located.

I can plot only the points (distorted, without a shapefile - see below), but as soon as I try to overlay this on the states shapefile, my code breaks. @atkissoncj Is this the right forum to post code when we encounter issues like this?

image
atkissoncj commented 5 days ago

See the urbnmapr documentation. It seems that this is based on something called fiftystater. My guess is that doesn't allow for non-states (e.g., Virgin Islands, Puerto Rico, etc.). The projection they use likely doesn't accommodate points so far away. When you do it without territories, does it work?

atkissoncj commented 5 days ago

@atkissoncj Is this the right forum to post code when we encounter issues like this?

Yes

voglerdaniel commented 5 days ago

See the urbnmapr documentation. It seems that this is based on something called fiftystater. My guess is that doesn't allow for non-states (e.g., Virgin Islands, Puerto Rico, etc.). The projection they use likely doesn't accommodate points so far away. When you do it without territories, does it work?

Thanks! Unfortunately filtering the data down to only the 50 US states does not resolve this issue. Output ends up looking like this:

image

atkissoncj commented 5 days ago

But what if you map the reduced set without the shape file? Is that still distorted?

voglerdaniel commented 5 days ago

But what if you map the reduced set without the shape file? Is that still distorted?

Not as bad, but ideally I'd like overlay it for consistency with other mappings.

image

atkissoncj commented 5 days ago

And is urbnmapr really what we should be using? Aren't there known issues with urbnmapr?

atkissoncj commented 5 days ago

Not as bad, but ideally I'd like overlay it for consistency with other mappings.

Yeah, sure, but at least it works.

voglerdaniel commented 5 days ago

And is urbnmapr really what we should be using? Aren't there known issues with urbnmapr?

Agreed, I'm looking at alternatives for this.

Another question you could ask is why we want to plot points in the first place, rather than summing flow over counties. The answer is that the county data in this file is a mess - 89% of the COUNTY_FIPS field is empty. We'd have to map each latitude and longitude to counties if we want to generate this map at a county level.

atkissoncj commented 5 days ago

@chayek Can you share code here (or point to the line) that will allow us to get points on a shapefile?

atkissoncj commented 5 days ago

Create function that allows you to take in points and the shape file level the user would like and creates a good, consistent map. @voglerdaniel : note that this has been made into a feature. Feel free to remove it as a feature if another feature already exists that will do this and note the feature that will close this concern.

npovejsil commented 4 days ago

Is this resolved by usmap package now?

voglerdaniel commented 4 days ago

The USMap package solved part of the problem - I can now overlay points on a states shapefile. But the distortion problem still exists: image @chayek and I are working on addressing it

atkissoncj commented 4 days ago

Is usmap the package that we'll be using? Or will we be building a different dependency?

Jihyeonbae commented 4 days ago

https://stackoverflow.com/questions/58676661/geom-sf-mapping-points-shapes These steps helped me overlay points on external shape files (not urbnmpr).

voglerdaniel commented 2 days ago

Closing - this functionality will be covered by #24