Skip to content

Commit

Permalink
Merge pull request #54 from bradlindblad/hotfix-vignette_issues
Browse files Browse the repository at this point in the history
Hotfix vignette issues
  • Loading branch information
bradlindblad authored Jan 23, 2022
2 parents 8708f9e + 77f65ae commit 0bc6cba
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# tidyUSDA (development version)

# tidyUSDA 0.3.3
* Fixed issue where vignette was not building correctly

# tidyUSDA 0.3.2
* Added error catch to https API calls

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![CRAN status](https://www.r-pkg.org/badges/version/tidyUSDA)](https://CRAN.R-project.org/package=tidyUSDA)
[![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/tidyUSDA)](https://cran.r-project.org/package=tidyUSDA)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.6.1-6666ff.svg)](https://cran.r-project.org/)
[![Codecov test coverage](https://codecov.io/gh/bradlindblad/tidyusda/branch/master/graph/badge.svg)](https://codecov.io/gh/bradlindblad/tidyusda?branch=master)
[![Codecov test coverage](https://codecov.io/gh/bradlindblad/tidyusda/branch/master/graph/badge.svg)](https://app.codecov.io/gh/bradlindblad/tidyusda?branch=master)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![pkgdown](https://github.com/bradlindblad/tidyUSDA/actions/workflows/pkgdown.yaml/badge.svg?branch=master)](https://github.com/bradlindblad/tidyUSDA/actions/workflows/pkgdown.yaml)

Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Fix issue where API call did not fail gracefully, per Brian Ripley request.
Fix issue where vignette failed to build per Brian Ripley email.

## Test environments
* local Linux Mint 20.2, R 4.1.0
Expand Down
Binary file added images/vignette_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/vignette_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 12 additions & 6 deletions vignettes/using_tidyusda.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
title: "Using tidyUSDA"
output: rmarkdown::html_vignette
output:
rmarkdown::html_vignette:
self_contained: no
vignette: >
%\VignetteIndexEntry{Using tidyUSDA}
%\VignetteEngine{knitr::rmarkdown}
Expand Down Expand Up @@ -68,7 +70,7 @@ There are many different geography levels. Currently there is only support for p

Now that we're a little more clear on what we can input, let's use our main function for data pulling.

```{r, results = "hide"}
```{r, eval = FALSE}
# Get count of operations with sales in 2017
ops.with.sales <- tidyUSDA::getQuickstat(
sector=NULL,
Expand All @@ -93,24 +95,28 @@ Note that I set *geometry = TRUE* in order to include the geometry feature that
At this point, I have a dataframe with a rather verbose number of data fields. If you set *geometry = TRUE*, you will have even more columns. The main data point from Quick Stats will be in the 'Value' field. Feel free to filter the data frame for the fields you actually need at this point.

Now let's see what the data looks like with a basic choropleth map.
```{r}
```{r, eval = FALSE}
# Plot this data for each state
tidyUSDA::plotUSDA(df = ops.with.sales)
```

*Note: it is a known issue that the RStudio graphics device on macOS can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the [tmap](https://github.com/mtennekes/tmap) package or [leaflet](https://rstudio.github.io/leaflet/).*
![](https://github.com/bradlindblad/tidyUSDA/blob/master/images/vignette_1.png?raw=true)

*Note: it is a known issue that the RStudio graphics device on macOS can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the [tmap](https://github.com/r-tmap/tmap) package or [leaflet](https://rstudio.github.io/leaflet/).*

OK wow so it looks like all the farms in the country are in Texas But wait a second, Texass is huge as far as landmass, and the relative size of the farms are smaller on balance, so maybe we should look at this a different way.

When we grabbed our data with getQuickstat above, we set weighted_by_area = TRUE, which creates a new field that,as you guessed, weights our main value by the land area in that county or state.

This gives us a bunch of really small numbers that don't make sense, but for our purposes of mapping, they'll do.

```{r}
```{r, eval = FALSE}
tidyUSDA::plotUSDA(df = ops.with.sales, fill_by = 'value_per_sq_mile')
```

![](https://github.com/bradlindblad/tidyUSDA/blob/master/images/vignette_2.png?raw=true)

Ahh, much better. Now we have a true plot showing the number of operations per square mile.

## Taking it further
Expand All @@ -125,4 +131,4 @@ You can report a bug or request new features at [https://github.com/bradlindblad
[1] (https://www.usda.gov/media/press-releases/2019/04/11/2017-census-agriculture-data-now-available)

## Important note
This product uses the NASS API but is not endorsed or certified by NASS.
This product uses the NASS API but is not endorsed or certified by NASS.

0 comments on commit 0bc6cba

Please sign in to comment.