class: center, middle, inverse, title-slide # Data Visualization ## Getting help ### Andrew Irwin,
a.irwin@dal.ca
### Math & Stats, Dalhousie University ### 2021-02-04 (updated: 2021-01-18) --- class: middle ## What to do when you are stuck? * How do I ... ? * Why did R do X when I wanted it to do Y? * My code doesn't work! * Help!! --- class: middle, inverse ## Learning technical skills is challenging * There are many ways to approach a task * You need to figure out how to describe what you want to accomplish and how to do it * You need to evaluate your decisions -- is that hard-won figure effective? * You need a strategy for making notes and building your own knowledge * Even small errors can be hard to find and cause a lot of frustration --- class: middle ## Ways to get help * Finding and fixing mistakes * Learning from examples * Remembering what you learned before * Learning something new * Asking questions --- ## Finding and fixing mistakes ```r gapminder %>% filter(country == "Canada", country == "Iran") ``` ``` ## # A tibble: 0 x 6 ## # … with 6 variables: country <fct>, continent <fct>, year <int>, ## # lifeExp <dbl>, pop <int>, gdpPercap <dbl> ``` -- ```r gapminder %>% filter(country == "Canada" | country == "Iran") # logical "or" ``` ``` ## # A tibble: 24 x 6 ## country continent year lifeExp pop gdpPercap ## <fct> <fct> <int> <dbl> <int> <dbl> ## 1 Canada Americas 1952 68.8 14785584 11367. ## 2 Canada Americas 1957 70.0 17010154 12490. ## 3 Canada Americas 1962 71.3 18985849 13462. ## 4 Canada Americas 1967 72.1 20819767 16077. ## 5 Canada Americas 1972 72.9 22284500 18971. ## 6 Canada Americas 1977 74.2 23796400 22091. ## 7 Canada Americas 1982 75.8 25201900 22899. ## 8 Canada Americas 1987 76.9 26549700 26627. ## 9 Canada Americas 1992 78.0 28523502 26343. ## 10 Canada Americas 1997 78.6 30305843 28955. ## # … with 14 more rows ``` --- ## Finding and fixing mistakes ```r gapminder %>% filter(country == "Canada" | country == "Iran") %>% ggplot(aes(x = Year, y = LifeExp, color = Country)) + geom_point() ``` ``` ## Error in FUN(X[[i]], ...): object 'Year' not found ``` ![](14-getting-help_files/figure-html/unnamed-chunk-3-1.png)<!-- --> --- ```r gapminder %>% filter(country == "Canada" | country == "Iran") %>% ggplot(aes(x = year, y = lifeExp, color = country)) + geom_point() ``` ![](14-getting-help_files/figure-html/unnamed-chunk-4-1.png)<!-- --> --- class: middle # Learning from examples Look in the **Examples** section of `?geom_line` ```r ggplot(economics, aes(unemploy, date)) + * geom_line(orientation = "y") ``` ![](14-getting-help_files/figure-html/unnamed-chunk-5-1.png)<!-- --> --- class: middle # Learning from examples .pull-left[ ```r ggplot(economics, aes(unemploy, date)) + geom_line(orientation = "y") ``` ![](14-getting-help_files/figure-html/unnamed-chunk-6-1.png)<!-- --> ] .pull-right[ ```r ggplot(economics, aes(unemploy, date)) + * geom_line() ``` ![](14-getting-help_files/figure-html/unnamed-chunk-7-1.png)<!-- --> ] --- class: middle # Remembering what you learned before How do I change the x and y axis labels? * Google search. Add "R" to your search. * Know which sites you like to read * Learn to read documentation -- more condensed information * https://ggplot2.tidyverse.org/ especially "cheatsheet" and "reference" * Scales > Axis > Labs: https://ggplot2.tidyverse.org/reference/labs.html * Make notes for yourself --- class: middle # Learn something new How do I set the limits, tick marks, and numbering on an axis? * ggplot2 tidyverse "Scales": `xlim`, `ylim` * Search. * Find `theme` * Find `scale_x_discrete(name, breaks, labels, limits)` * Also `scale_x_continuous(name, breaks, lables, limits, trans)` * Try an example from the help page (or internet) --- class: middle ```r p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() p1 + scale_x_continuous(name = "Displacement", limits = c(2, 6), breaks = c(2, 4, 6), labels = c("Two", "Four", "Six")) ``` ![](14-getting-help_files/figure-html/unnamed-chunk-8-1.png)<!-- --> Read a bit of `?c` (combine values into a vector or list). --- class: middle # Asking questions You are still stuck. How do you ask for help? * What are you trying to do? * What have you tried? * What was the result (output, graphic, error message)? * What do you think the problem might be? --- class: middle # Summary * Learning computing skills is a never-ending task * Using reference material, blogs, and books is a learned skill that you can get better at * Try different sources until you learn what you like to learn from the most (and sometimes try other sources) * Asking questions is a valuable skill. Clearly expressing your question so that someone else can read it will often help you solve the problem by yourself. * It gets easier with practice: posing questions, understanding the answers, and remembering how it all fits together --- class: middle # Further reading * Course notes * Two or more sources referenced in earlier lessons --- class: middle, inverse ## Task Assignment 2 asks you to learn some new skills and describe what you learned.