---
title: "Sample Workflow for Labs"
author: "Place your name goes here"
output:
  html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

::: {.task .heading style="color: green;"}
**Handout date:** *Today*

**Due date:** *As announced in one or two weeks*

**Submission Format:** Submit your lab as R Markdown document `LabWorkFlowYourName.rmd` to eLearning's *SumitLabWorkFlow* link in the **Labs** folder. Put your name in *quotation marks* behind the author's keyword in the YAML header of the Markdown file. Make sure that your R Markdown document knits, that is, renders, properly into an `html` document. Otherwise, we will *not* be able to grade your lab!

*This lab counts xx points toward your final grade.*
:::

::: {.task .heading style="color: red;"}
Your graded lab answers have obtained *yy* out of xx points?
:::

::: {.task .heading style="color: green;"}
## Objectives:

In this workflow lab you will,

1.  generate maps with `R`, and

2.  type-set two basic equations.

## Color codes:

-   Lab questions are formatted in green.
:::

-   Your answers are formatted in black. Type your answers were is says *Your answer goes here*.

::: {.task .heading style="color: red;"}
-   The graded Markdown file with show our comments to your answers in red.
:::

::: {.task .heading style="color: green;"}
## Workflow:

-   You use this Markdown document as template to insert your answers and necessary R code chunks at the *Your answer goes here* locations by overwriting the text string "*Your answer goes here*".
-   For R code chunks make sure to use `Cntr-Alt-I` to mark the beginning and end of the chunk. In-between the beginning and end of the chunk you enter your R commands to perform the requested tasks.
-   You have two options to insert R code into the chunk depending on what works better for you.
    -   For code that does *not dependent* on the results of previously run chunks you can enter your commands directly into the chunk. You can then test your commands with the chunk's directive `Run Current Chunk`.
    -   For commands that *dependent* on results of previously issued chunks it is more elegant to have a separate R script with all the necessary commands and run all commands from the script editor. Intermediate results are then available to the script in the `Environment`. Once your script executes properly, you can copy the necessary commands into their appropriate code chunks in your R Markdown document.
    -   Alternatively, for commands that *dependent* on the results of previously issued chunks you can use in Markdown the chunk directive `Run All Chunks Abow`. This way intermediate results are available to your currently active chunk.

# Task 1: Generate Maps (zz points)

Please visit the online help of the `TexMix` package. The `tractShp` object holds 2018 American Community Survey data for all 529 census tracts of Dallas County as well as their geographic boundaries. Please see the overview map below, which also superimposes lakes and main highways for orientation purposes on the census tract layout. Notice the formatting options in the chunk's header. The two airport census tracts Love Field and DFW are excluded, because they have zero population count and therefore no data for many census fields.

```{r baseMap, fig.width=8, fig.height=8, fig.align='center',echo=FALSE, message=FALSE, fig.cap='Base Map of Dallas Census Tracts'}
library(TexMix)                                              # For data and mapping functions
library(sp)                                                  # For map manipulations
validTractShp <- tractShp[tractShp$NIGHTPOP > 0, ]           # Remove 2 tracts with zero population
plot(tractShp, col="white", border="grey", axes=TRUE,        # Map all tracts
     main="Dallas Census Tracts with Lakes and Highways")   
plot(lakesShp, col="turquoise", border="turquoise",add=TRUE) # Superimpose lakes
plot(hwyShp, col="cornsilk3", lwd=3, add=TRUE)               # Superimpose highways
```

Your objective is to generate thematic maps for the categorical variable `CITYPERI` and the metric variable `MEDVALHOME` with the mapping functions in the `TexMix` package.

[a] Map the categorical variable `CITYPERI` with superimposed lakes and highways by using the function `mapColorQual( )`. Provide proper map and legend titles. (zzz points)
:::

*Your code chunk goes here.*

::: {.task .heading style="color: green;"}
[b] Map the metric variable `MEDVALHOME` with superimposed lakes and highways by using the function `mapColorRamp( )`. Provide proper map and legend titles. (zzz points)
:::

*Your code chunk goes here.*

::: {.task .heading style="color: green;"}
[c] Map the metric variable `MEDVALHOME` with superimposed lakes and highways as variation around the median by using the function `mapBiPolar( )`. Provide proper map and legend titles. (zzz points)
:::

*Your code chunk goes here.*

::: {.task .heading style="color: green;"}
[d] Discuss which map in either [b] or [c] of the median home value highlights more informative census tracts with low and high home values.
:::

*Your answer goes here.*

::: {.task .heading style="color: green;"}
# Task 2: Typeset an equation (zz points)

Your task is provide the equation for the arithmetic mean either as inline or display equation.

[a] Within the line below insert the arithmetic mean equation as inline formula. (zzz points)
:::

This is an inline equation *the inline equation goes here* of the arithmetic mean.

::: {.task .heading style="color: green;"}
[b] Insert the arithmetic mean below this line as a display formula. (zzz points)
:::

*The display equation goes here.*

::: {.task .heading style="color: green;"}
[c] How do inline and display equations differ? (zzz points)
:::

*Your answer goes here.*
