Skip to content

Commit

Permalink
updates to presentation 1, 2, 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ThildeBT committed Oct 30, 2024
1 parent aa499b7 commit c663eb4
Show file tree
Hide file tree
Showing 23 changed files with 3,029 additions and 1,420 deletions.
173 changes: 89 additions & 84 deletions Teachers/Presentations/HTMLs/presentation1.html

Large diffs are not rendered by default.

2,506 changes: 1,469 additions & 1,037 deletions Teachers/Presentations/HTMLs/presentation2.html

Large diffs are not rendered by default.

1,183 changes: 1,183 additions & 0 deletions Teachers/Presentations/HTMLs/presentation3.html

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions Teachers/Presentations/presentation1.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ Some features can only be added when you are in Source mode. E.g [write blue tex
Code chunks are where the code is added to the document. Click the green button `+c` and a grey code chunk will appear with `'{r}'` in the beginning. This mean that it is an R code chunk. It is also possible to insert code chunks of other coding language.\
For executing the code, press the `Run` button in the top right of the chunk to evaluate the code.

If you have ever worked with an R script, a code chunk is just like a part of an R script.

```{r}
```
Expand Down Expand Up @@ -147,27 +145,33 @@ getwd()

**Set working directory, setwd()**

The working directory can changed BUT when working with Quarto this only influences individual code chunks. In opposition, a changing of wd within a classic .R script affects the document globally - we will not cover .R script in this course.\
The working directory can changed BUT when working with Quarto this only influences individual code chunks. In opposition, a changing of wd within an `.R script` affects the document globally - we will not cover `.R scripts` in this course.\
There are two type of paths, absolute paths (from root to desired location) and relative paths (from current location to desired location):

**Absolute path:**
*Absolute path:*

```{r, eval=FALSE}
setwd("/Users/kgx936/Desktop/HeaDS/GitHub_repos/FromExceltoR")
```

**Relative path:**
*Relative path:*

```{r, eval=FALSE}
setwd('./Exercises/')
```

**Navigate up in the directory tree (..)**
*Navigate up in the directory tree (..)*

```{r}
```{r, eval=FALSE}
setwd('../Teachers')
```

**Pointing to a dataset**

```{r, eval=FALSE}
load('/Users/kgx936/Desktop/HeaDS/GitHub_repos/FromExceltoR/Data/MyData.Rdata')
```

## Variable assignment

In R we use an arrow for variable assignment. You may call your almost variables whatever you like. [DO NOT]{.underline}: use special characters in variable names, i.e. &, ), \$ etc. or make spaces in naming.
Expand Down
36 changes: 18 additions & 18 deletions Teachers/Presentations/presentation3.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project:

## Importing libraries and data

```{r}
```{r, warning=FALSE,message=FALSE}
library(readxl)
library(writexl)
library(tidyverse)
Expand All @@ -34,15 +34,16 @@ Making the data more fun to plot.

```{r}
# Define 5 colors and their respective ratios
colors <- c(rep("Red", 40),
rep("Blue", 20),
rep("Yellow",30),
rep("Green", 20),
rep("Purple",40))
set.seed(123) # For reproducibility
colors <- c(rep("Red", 50), # 50 rows with Red
rep("Blue", 30), # 30 rows with Blue
rep("Yellow", 30), # 30 rows with Yellow
rep("Green", 20), # 20 rows with Green
rep("Purple", 20)) # 20 rows with Purple
# Shuffle the colors to mix them randomly
colors <- sample(colors)
colors <- sample(colors, replace = TRUE)
# Add the 'Flower.Color' column to the iris dataset
iris$Flower.Color <- colors
Expand Down Expand Up @@ -163,14 +164,9 @@ p
# Show p with new labels
p + labs(x = 'Flower Color', y = 'Count')
# Show p (nothing has changed)
p
# Save p with new lables in p (overwrite / reassign)
p <- p + labs(x = 'Flower Color', y = 'Count')
p2 <- p + labs(x = 'Flower Color', y = 'Count')
# Show p (lables have changed)
p
```

Color by species. The bars are stacked by default.
Expand Down Expand Up @@ -267,17 +263,21 @@ p <- p + coord_flip()

Since we are working with colors, we can change the colors of the bars to match the groups.

R color chart [here](http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf)

```{r}
# Define color palette
color_palette <- c("Red" = "red",
"Blue" = "blue",
"Yellow" = "yellow",
"Green" = "green",
"Purple" = "purple")
color_palette <- c("Red" = "red3",
"Blue" = "cornflowerblue",
"Yellow" = "lightgoldenrod1",
"Green" = "darkolivegreen2",
"Purple" = "darkorchid3")
p <- p +
aes(fill = Flower.Color) + # add the fill ascetics
scale_fill_manual(values = color_palette) # set the fill color according to the color palette
print(p)
```

## Bar chart with `geom_col`
Expand Down
Binary file modified Teachers/Slideshow/FromExceltoR.pdf
Binary file not shown.
Binary file modified Teachers/Slideshow/FromExceltoR.pptx
Binary file not shown.
173 changes: 89 additions & 84 deletions docs/Presentations/presentation1.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Presentations/presentation2.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ <h2 class="anchored" data-anchor-id="check-working-directory">Check working dire
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">getwd</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "/Users/srz223/Desktop/DataLab/FromExceltoR/Teachers/Presentations"</code></pre>
<pre><code>[1] "/Users/kgx936/Desktop/HeaDS/GitHub_repos/FromExceltoR/Teachers/Presentations"</code></pre>
</div>
</div>
</section>
Expand Down
Loading

0 comments on commit c663eb4

Please sign in to comment.