Skip to content

Commit

Permalink
Add an instructional diagram to viz lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
regetz committed Jan 28, 2025
1 parent e935cf3 commit 9df4a9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Binary file added materials/images/ggplot-data-to-viz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions materials/sections/visualization-ggplot-leaflet.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ library(DT) # interactive tables
```


2. Load the data table directly from the [KNB Data Repository: Daily salmon escapement counts from the OceanAK database, Alaska, 1921-2017](https://knb.ecoinformatics.org/view/doi%3A10.5063%2FP26WJJ). Navigate to the link above, hover over the "Download" button for the `ADFG_firstAttempt_reformatted.csv`, right click, and select "Copy Link".

```{r}
Expand Down Expand Up @@ -106,7 +105,6 @@ colnames(escape)

:::


::: callout-note
### Exercise

Expand All @@ -130,7 +128,8 @@ The chunk above used some dplyr commands that we've used previously, and some th

## Plotting with `ggplot2`

### Essentials components
### Essential components

First, we’ll cover some `ggplot2` basics to create the foundation of our plot. Then, we’ll add on to make our great customized data visualization.

::: {.callout-caution icon=false}
Expand Down Expand Up @@ -179,6 +178,35 @@ ggplot(data = annual_esc,
geom_col()
```

Let's take a minute to review a few of the core components of a ggplot visualization, and see how they relate back to the data that we are plotting. Consider this small subset of 12 records from our escapement data, and a corresponding scatterplot of daily fish counts across 5 days for a particular region.

:::{.column-body-outset}
![](images/ggplot-data-to-viz.png){.lightbox width=100% fig-align="center"}
:::

<!---
figure_data <- escape %>%
filter(sasap_region == "Kodiak",
"1950-07-26" <= sample_date,
sample_date <= "1950-07-30",
0 < daily_count,
species %in% c("Pink", "Sockeye"))
figure_data %>%
select(sample_date, location, species, daily_count) %>%
knitr::kable() %>%
kableExtra::kable_styling()
figure_data %>%
ggplot +
geom_point(aes(sample_date, daily_count, colour=species, shape=location),
size=3) +
scale_x_date("Sample date") +
scale_y_log10("Daily count", label=scales::comma) +
scale_shape_discrete("Location") +
scale_color_discrete("Species") +
theme_light()
--->


### Looking at different geoms

Having the basic structure with the essential components in mind, we can easily change the type of graph by updating the `geom_*()`.
Expand Down

0 comments on commit 9df4a9f

Please sign in to comment.