BaşlayınÜcretsiz Başlayın

walk() for printing cleaner list outputs

Now you will try one more use of walk(), specifically creating plots using walk(). In the previous exercise, you printed some lists, and you saw that printing lists is much cleaner using walk() than using the base R way. You can also use walk() to display multiple plots sequentially.

Here, use your map() knowledge along with ggplot2 functions to create a graph for the first ten elements of gap_split and then display each graph with walk().

Bu egzersiz

Foundations of Functional Programming with purrr

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Load the gap_split dataset.
  • map2() over the first 10 elements of gap_split, and the first 10 names of gap_split.
  • Then walk() over the new plots object and supply print() as an argument to print all plots.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Load the gap_split data
data(___)

# Map over the first 10 elements of gap_split
plots <- map2(___[1:10], 
              names(___[1:10]), 
              ~ ggplot(___, aes(year, lifeExp)) + 
                geom_line() +
                labs(title = ___))

# Object name, then function name
walk(___, ___)
Kodu Düzenle ve Çalıştır