class: center, middle, inverse, title-slide # Data visualization ## Common questions and answers ### Ben Baumer ### SDS 192Sep 9, 2020(
http://beanumber.github.io/sds192/lectures/sds192_common_questions.html
) --- class: center, middle, inverse # Announcements --- ## About DataCamp... .pull-left[ ![](https://www.datacamp.com/datacamp.png) ] -- .pull-right[ - [A Multimillion-Dollar Startup Hid A Sexual Harassment Incident By Its CEO — Then A Community of Outsiders Dragged It Into the Light](https://www.buzzfeednews.com/article/daveyalba/datacamp-sexual-harassment-metoo-tech-startup) ] --- ## `bbplot` from the BBC .footnote[[How the BBC Visual and Data Journalism team works with graphics in R](https://medium.com/bbc-visual-and-data-journalism/how-the-bbc-visual-and-data-journalism-team-works-with-graphics-in-r-ed0b35693535)] .pull-left[ ![](https://cdn-images-1.medium.com/max/1600/0*DDRU1L5LIJkgDBxd.png) ] -- .pull-right[ <blockquote class="twitter-tweet"><p lang="en" dir="ltr">I tried a ggplot for the last graphic! Here is a link to my Github for the code and data table:<a href="https://t.co/B1k83Y0DTd">https://t.co/B1k83Y0DTd</a> <a href="https://t.co/zV4MZNdMe0">pic.twitter.com/zV4MZNdMe0</a></p>— Sarah Gillespie (@SarahG4567) <a href="https://twitter.com/SarahG4567/status/1113695016696860673?ref_src=twsrc%5Etfw">April 4, 2019</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> ] --- class: center, middle, inverse # Common questions and answers --- ## Three tips 1. Don't save your workspace...[**ever**](https://www.stat.ubc.ca/~jenny/STAT545A/block01_basicsWorkspaceWorkingDirProject.html#workspace-.rdata) 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 -- - [Further customizations](https://www.pipinghotdata.com/posts/2020-09-07-introducing-the-rstudio-ide-and-r-markdown/?s=09) are possible --- ## Piping > Like... what is piping? - `x %>% f(y)` is equivalent to `f(x, y)` - Why bother? ```r # piped form x %>% f(y) %>% g(z, a) %>% h() # nested form h(g(f(x, y), z, a)) ``` --- ## To pipe or not to pipe? - Add new column called `total` ```r # "base" R syntax present$total <- present$boys + present$girls ``` -- ```r # Using mutate() but no pipe # same result present <- mutate(present, total = boys + girls) ``` -- ```r # Using mutate() and the pipe # same result *present <- present %>% * mutate(total = boys + girls) ``` -- - Much, much, more on this later... --- ## Chunks vs. Text > I was slightly confused by the difference between R chunks and regular text. -- - A chunk looks like this ````markdown ```{r} qplot(mtcars, x = cyl, y = mpg, geom = "line") ``` ```` --- ## Error messages .pull-left[ .center[![](https://media.giphy.com/media/pDdzX4l9jqA80/giphy.gif)] ] .pull-right[ > 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! --- ## 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](https://www.rstudio.com/resources/cheatsheets/) - We'll focus on a small set of functions... -- - ...that we will use a lot! --- ## 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.** <blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Searching for good analogy for <a href="https://twitter.com/hashtag/rstats?src=hash">#rstats</a> Console vs. R Markdown document. Does having a conversation vs. writing a speech work?</p>— Ben Baumer (@BaumerBen) <a href="https://twitter.com/BaumerBen/status/907281798585077760">September 11, 2017</a></blockquote> <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script> --- ## 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) --- ## [chunk options](https://yihui.name/knitr/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 -- - <mark>`message=FALSE`</mark> : 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