Skip to content

Commit

Permalink
fixing geom_sf issue in vignette to pass CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
lawinslow committed Mar 26, 2018
1 parent 407ab4b commit 724988d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ figure/
^README\.Rmd$
^README\.md$
^README-.*\.png$
^vignettes/wqp_lake_linking_example_cache/.*$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: hydrolinks
Type: Package
Title: Hydrologic Network Linking Data and Tools
Version: 0.9.2
Version: 0.9.3
Authors@R: c( person("Tobi", "Hahn", role = c("aut"),
email = "hahnt2@rpi.edu"),
person("Luke", "Winslow", role = c("aut", "cre"),
Expand Down
55 changes: 37 additions & 18 deletions vignettes/wqp_lake_linking_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ to link and visualize.
library(dataRetrieval)
library(hydrolinks)
library(USAboundaries)
library(ggplot2)
library(gridExtra)
#library(ggplot2)
#library(gridExtra)
library(sf)
lsites = whatWQPsites(siteType ="Lake, Reservoir, Impoundment", statecode='US:55')
```

At the point of this Vignette generation, there were `r length(unique(lsites$MATCH_ID))` unique sites
At the point of this Vignette generation, there were `r length(unique(lsites$MonitoringLocationIdentifier))` unique sites
returned by this query.

Now, lets link all these sites to the NHDH. After the initial point-in-polygon linking, I will take
Expand All @@ -66,29 +66,48 @@ tbl = data.frame(Link=c('Point-in-polygon', 'Centroid', 'Unlinked', 'Total'),
kable(tbl, 'html') %>% kable_styling()
```

Lastly, lets visualize these sites. Little `grid.arrange` to mash them all together.
Lastly, lets visualize these sites. Just mash them all together. (also left in bleeding edge `geom_sf` code that fails on CRAN).

```{r mapfigs, echo=TRUE, warning=FALSE, message=FALSE, fig.width=8, fig.height=8}
wi = USAboundaries::us_boundaries()[USAboundaries::us_boundaries()$geoid %in% c('55'),]
all_points = st_as_sf(lsites, coords = c("LongitudeMeasure", "LatitudeMeasure"), crs = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
par(mfrow=c(2,2), mar=c(0,0,0,0))
plot(st_geometry(wi))
plot(st_geometry(all_points), col='darkorange2', add=TRUE, pch=16)
legend('topright', legend=' ', title='a) all WQP points', bty='n')
pippoints = subset(all_points, MonitoringLocationIdentifier %in% linked_lakes$MATCH_ID)
plot(st_geometry(wi))
plot(st_geometry(pippoints), col='darkorchid3', add=TRUE, pch=16)
legend('topright', legend=' ', title='b) all linked point-in-poly', bty='n')
centpoints = subset(all_points, MonitoringLocationIdentifier %in% linked_lcent$MATCH_ID)
plot(st_geometry(wi))
plot(st_geometry(centpoints), col='darkorchid3', add=TRUE, pch=16)
legend('topright', legend=' ', title='c) all linked centroid', bty='n')
# gall = ggplot(all_points) +
# geom_sf(data=wi, fill='grey') +
# geom_sf(size=0.5, color='darkorange2') + ylim(42, 47) + xlim(-93, -86.5) +
# ggtitle('a) all WQP points')
#
# glink = ggplot(subset(all_points, MonitoringLocationIdentifier %in% linked_lakes$MATCH_ID)) +
# geom_sf(data=wi, fill='grey') +
# geom_sf(size=0.5, color='dodgerblue') + ylim(42, 47) + xlim(-93, -86.5) +
# ggtitle('b) all linked point-in-poly')
#
# gcent = ggplot(subset(all_points, MonitoringLocationIdentifier %in% linked_lcent$MATCH_ID)) +
# geom_sf(data=wi, fill='grey') +
# geom_sf(size=0.5, color='darkorchid3') + ylim(42, 47) + xlim(-93, -86.5) +
# ggtitle('c) all linked centroid')
#
#
# grid.arrange(gall, glink, gcent, nrow = 2)
gall = ggplot(all_points) + geom_sf(data=wi, fill='grey') +
geom_sf(size=0.5, color='darkorange2') + ylim(42, 47) + xlim(-93, -86.5) +
ggtitle('a) all WQP points')
glink = ggplot(subset(all_points, MonitoringLocationIdentifier %in% linked_lakes$MATCH_ID)) +
geom_sf(data=wi, fill='grey') +
geom_sf(size=0.5, color='dodgerblue') + ylim(42, 47) + xlim(-93, -86.5) +
ggtitle('b) all linked point-in-poly')
gcent = ggplot(subset(all_points, MonitoringLocationIdentifier %in% linked_lcent$MATCH_ID)) +
geom_sf(data=wi, fill='grey') +
geom_sf(size=0.5, color='darkorchid3') + ylim(42, 47) + xlim(-93, -86.5) +
ggtitle('c) all linked centroid')
grid.arrange(gall, glink, gcent, nrow = 2)
```


0 comments on commit 724988d

Please sign in to comment.