Scales

  1. Choose one or two of your previous plots, and give the scales a proper name.

    Hint: Use one or more scale_...() functions.

  2. What happens if you call the same scale_...() function twice in a plot?

  3. Add an overview over all available colorblind friendly Brewer scales to your rmarkdown document.

    Hint: Insert a code chunk containing RColorBrewer::display.brewer.all(colorblindFriendly = TRUE)

  4. Choose an appealing scale for one of your plots that use the “color” or “fill” aesthetics. Apply it with scale_..._brewer("<name>", palette = "<palette>")

    Hint: Use scale_..._distiller() if you have mapped a continuous variable.

  5. Practice Markdown: Create sections, subsections, item lists, emphasized and bold text, … .

Coordinate systems

  1. Create a flipped boxplot of fuel economy by transmission type.

  2. Plot highway vs. city fuel economy with an additional geom_abline() layer. How do you set a 45° degree for the diagonal line?

  3. Try to “estimate” an approximate ratio between the two economy measures by tweaking the slope argument to geom_abline().

Theming

  1. Choose your favorite among the predefined themes.

    Hint: All start with theme_...(), but watch out for theme_set().

  2. Apply theme(legend.position = "bottom") to a plot with a color or fill legend. What happens if you then apply theme_bw()? Why?

plotly

  1. Convert one of the scatterplots you generated previously using the following pattern:

    p <-
      data %>% 
      ___ %>%
      ggplot(aes(___)) +
        geom_point()
    
    plotly::ggplotly(p)
  2. Experiment with the plotly controls on the top right.

  3. Add extra aesthetics to the scatterplot. Hover with the mouse over the points:

    p <-
      data %>% 
      ___ %>%
      ggplot(aes(___, extra1 = manufacturer, extra2 = model)) +
        geom_point()
    
    plotly::ggplotly(p)
  4. Convert a bar plot or a histogram to plotly. How does this affect the tooltip?

  5. See https://plotly-book.cpsievert.me/linking-views-without-shiny.html for examples of linking two plots, or linking plots with other widgets. This requires the crosstalk package:

    install.packages("crosstalk")

leaflet

  1. Show the quakes data, or a subset, on a map:

    library(leaflet)
    quakes %>% 
      ___ %>% 
      leaflet() %>% 
      addTiles() %>% 
      addCircles()
  2. Add a popup to the tiles. Click on one of the circles

    Hint: Use str_c() or paste0() to concatenate text and data.

    library(leaflet)
    ___ %>% 
      addCircles()
  3. Explore further options in ?addTiles.

  4. See section 4.2.3 in https://plotly-book.cpsievert.me/linking-views-without-shiny.html for linking a map to a plot.

Copyright © 2018 Kirill Müller. Licensed under CC BY-NC 4.0.