+ - 0:00:00
Notes for current slide
Notes for next slide

Data visualization

Common questions and answers

Ben Baumer

SDS 192
Sep 9, 2020
(http://beanumber.github.io/sds192/lectures/sds192_common_questions.html)

1 / 14

Announcements

2 / 14

About DataCamp...

3 / 14

bbplot from the BBC

How the BBC Visual and Data Journalism team works with graphics in R

4 / 14

Common questions and answers

5 / 14

Three tips

  1. Don't save your workspace...ever

    1. Global Options -> General -> Workspace
6 / 14

Three tips

  1. Don't save your workspace...ever

    1. Global Options -> General -> Workspace
  1. Turn off notebook mode

    1. Global Options -> R Markdown -> Uncheck Show output inline...
6 / 14

Three tips

  1. Don't save your workspace...ever

    1. Global Options -> General -> Workspace
  1. Turn off notebook mode

    1. Global Options -> R Markdown -> Uncheck Show output inline...
  1. View knit documents in viewer pane

    1. Gearwheel -> Preview in Viewer Pane
6 / 14

Three tips

  1. Don't save your workspace...ever

    1. Global Options -> General -> Workspace
  1. Turn off notebook mode

    1. Global Options -> R Markdown -> Uncheck Show output inline...
  1. View knit documents in viewer pane

    1. Gearwheel -> Preview in Viewer Pane
6 / 14

Piping

Like... what is piping?

  • x %>% f(y) is equivalent to f(x, y)

  • Why bother?

# piped form
x %>%
f(y) %>%
g(z, a) %>%
h()
# nested form
h(g(f(x, y), z, a))
7 / 14

To pipe or not to pipe?

  • Add new column called total
# "base" R syntax
present$total <- present$boys + present$girls
8 / 14

To pipe or not to pipe?

  • Add new column called total
# "base" R syntax
present$total <- present$boys + present$girls
# Using mutate() but no pipe
# same result
present <- mutate(present, total = boys + girls)
8 / 14

To pipe or not to pipe?

  • Add new column called total
# "base" R syntax
present$total <- present$boys + present$girls
# Using mutate() but no pipe
# same result
present <- mutate(present, total = boys + girls)
# Using mutate() and the pipe
# same result
present <- present %>%
mutate(total = boys + girls)
8 / 14

To pipe or not to pipe?

  • Add new column called total
# "base" R syntax
present$total <- present$boys + present$girls
# Using mutate() but no pipe
# same result
present <- mutate(present, total = boys + girls)
# Using mutate() and the pipe
# same result
present <- present %>%
mutate(total = boys + girls)
  • Much, much, more on this later...
8 / 14

Chunks vs. Text

I was slightly confused by the difference between R chunks and regular text.

9 / 14

Chunks vs. Text

I was slightly confused by the difference between R chunks and regular text.

  • A chunk looks like this
```{r}
qplot(mtcars, x = cyl, y = mpg, geom = "line")
```
9 / 14

Error messages

I did not get stuck, but was a little bit panicked when I saw error messages

10 / 14

Error messages

I did not get stuck, but was a little bit panicked when I saw error messages

  • Train yourself to read them!
10 / 14

Error messages

I did not get stuck, but was a little bit panicked when I saw error messages

  • Train yourself to read them!

  • Don't be thrown by red text!

10 / 14

Memorizing functions

The most difficult part of this lab was getting used to the format of R. I have no coding experience and I don’t know how I’ll be able to memorize functions in the future.

  • Cheatsheets

  • We'll focus on a small set of functions...

11 / 14

Memorizing functions

The most difficult part of this lab was getting used to the format of R. I have no coding experience and I don’t know how I’ll be able to memorize functions in the future.

  • Cheatsheets

  • We'll focus on a small set of functions...

  • ...that we will use a lot!
11 / 14

Console vs. Markdown

I originally had a hard time understanding that I was in an R Markdown and what that meant but as the lab continued I realized that it was just like a notepad for my codes.

12 / 14

Copying-and-pasting

it was pretty simple since it was more or less just copying and pasting commands and seeing what they did

I noticed that when I copy and pasted directly from the console, the + sign that we used in some chunks prompted an error message when I tried to knit it. I had to manually remove the + sign and then the code ran smoothly.

13 / 14

Copying-and-pasting

it was pretty simple since it was more or less just copying and pasting commands and seeing what they did

I noticed that when I copy and pasted directly from the console, the + sign that we used in some chunks prompted an error message when I tried to knit it. I had to manually remove the + sign and then the code ran smoothly.

  • Solution: don't copy-and-paste (within reason)
13 / 14

chunk options

  • echo=FALSE: don't show the code
14 / 14

chunk options

  • echo=FALSE: don't show the code

  • eval=FALSE: don't evaluate the code

14 / 14

chunk options

  • echo=FALSE: don't show the code

  • eval=FALSE: don't evaluate the code

  • include=FALSE: don't show the code or the results

14 / 14

chunk options

  • echo=FALSE: don't show the code

  • eval=FALSE: don't evaluate the code

  • include=FALSE: don't show the code or the results

  • message=FALSE : don't show the messages

14 / 14

chunk options

  • echo=FALSE: don't show the code

  • eval=FALSE: don't evaluate the code

  • include=FALSE: don't show the code or the results

  • message=FALSE : don't show the messages

  • In general, I want to see your code and your results, but not your messages

14 / 14

chunk options

  • echo=FALSE: don't show the code

  • eval=FALSE: don't evaluate the code

  • include=FALSE: don't show the code or the results

  • message=FALSE : don't show the messages

  • In general, I want to see your code and your results, but not your messages

  • Soon, you will have a template that takes care of most of this for you

14 / 14

Announcements

2 / 14
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow