Skip to content

Commit 61bc3c6

Browse files
committed
fixes to psych ex w2
1 parent cfad389 commit 61bc3c6

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

pgt52m/week-2/psych-example.qmd

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You will create a figure like this:
4848
```{r}
4949
#| echo: false
5050
strategy_data <- data.frame(strategy, freq)
51-
ggplot(data = reg_data,
51+
ggplot(data = strategy_data,
5252
aes(x = reorder(strategy, freq, decreasing = TRUE),
5353
y = freq)) +
5454
geom_col(colour = "black", fill = "lightblue", width = 1) +
@@ -485,4 +485,31 @@ ggplot(data = strategy_data,
485485
486486
```
487487

488-
[Return](workshop.html) to the workshop page
488+
We have one more thing to do before we finish. The overlapping category
489+
labels are not great. One solution for this is to add "wrapping" to the
490+
labels so that they are not too long. We can use the `scales` package
491+
function `label_wrap(10)` to do this.
492+
493+
![](images/do_in_R.png) Add `labels = scales::label_wrap(10)` to the
494+
`scale_x_discrete()` command.
495+
496+
```{r}
497+
498+
strategy_data <- data.frame(strategy, freq)
499+
ggplot(data = strategy_data,
500+
aes(x = reorder(strategy, freq, decreasing = TRUE),
501+
y = freq)) +
502+
geom_col(colour = "black", fill = "lightblue", width = 1) +
503+
scale_x_discrete(name = "Strategy",
504+
expand = c(0, 0),
505+
labels = scales::label_wrap(10)) +
506+
scale_y_continuous(name = "Number of students",
507+
expand = c(0, 0),
508+
limits = c(0, 25)) +
509+
theme_classic()
510+
```
511+
512+
The number is the maximum number of characters in a line before it wraps
513+
to the next line.
514+
515+
## [Return](workshop.html#finished-w2) to the workshop page.

pgt52m/week-2/workshop.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,9 @@ ggplot(data = coat_data,
544544
545545
```
546546

547-
You're finished! {#finished-w2}
547+
You're finished!
548548

549-
# 🥳 Well Done! 🎉
549+
## 🥳 Well Done! 🎉 {#finished-w2}
550550

551551
![Artwork by @allison_horst: "but now its
552552
like"](images/r_first_then.png){fig-alt="A digital cartoon with two illustrations: the top shows the R-logo with a scary face, and a small scared little fuzzy monster holding up a white flag in surrender while under a dark storm cloud. The text above says 'at first I was like…'. The lower cartoon is a friendly, smiling R-logo jumping up to give a happy fuzzy monster a high-five under a smiling sun and next to colourful flowers. The text above the bottom illustration reads 'but now its like…'. "

0 commit comments

Comments
 (0)