Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions modules/Data_Input/Data_Input.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ R Projects are a super helpful feature of RStudio. They help you:

## Why projects?

"The chance of the `setwd()` command having the desired effect – making the file paths work – for anyone besides its author is 0%. It’s also unlikely to work for the author one or two years or computers from now. The project is not self-contained and portable."

- [Jenny Bryan](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/)
"The chance of the `setwd()` command having the desired effect – making the file paths work – for anyone besides its author is 0%. It’s also unlikely to work for the author one or two years or computers from now. The project is not self-contained and portable." - [Jenny Bryan](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/)

**Let's go over how to create and use an R Project!**

```{r, fig.alt="If the first line of your R script is setwd C:Users jenny path that only I have I will come into your office and SET YOUR COMPUTER ON FIRE.", out.width = "40%", echo = FALSE, fig.align='center'}
knitr::include_graphics("images/Jenny_fire.jpg")
```


## New R Project

Let's make an R Project so we can stay organized in the next steps. Click the new R Project button at the top left of RStudio:
Expand Down Expand Up @@ -244,7 +247,9 @@ knitr::include_graphics("images/files.jpg")

## Checking the working directory

Run the `getwd()` function to determine your working directory.
Run the `getwd()` function to determine your working directory.

You can also click the ![R Logo](images/files_gear.png){width=25px} in the Files pane > Go To Working Directory.

```{r eval=FALSE}
# Get the working directory
Expand Down
Binary file added modules/Data_Input/images/Jenny_fire.jpg
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 modules/Data_Input/images/files_gear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions resources/palette.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Script to create color palette
library(tidyverse)

# Break data down into grid
r_colors <-
data.frame(
COLOR = colors(),
COL = rep(seq(1, 9), each = 73),
ROW = rep(seq(1, 73), times = 9)
)

# Get RGB values to help with label coloring, stick into the data frame
r_colors <-
cbind(r_colors,
map_dfr(map(r_colors$COLOR, col2rgb), ~ as.data.frame(t(.x))))

# Black label if the color is lighter
r_colors <-
r_colors |>
mutate(label_color = case_when(red + blue + green > 510 ~ "black", TRUE ~ "white"))

# Make the palette
ggplot(r_colors, aes(x = COL, y = ROW)) +
geom_tile(fill = r_colors$COLOR) +
scale_fill_manual(values = r_colors$COLOR) +
geom_text(aes(label = COLOR),
color = r_colors$label_color,
size = 3) +
theme_void() +
theme(legend.position = "none")

# Save
ggsave("resources/palette.jpg", height = 10, width = 11)
Binary file added resources/palette.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading