palmerpenguins R Package

repository·main·Indexed 20 days ago

https://github.com/allisonhorst/palmerpenguins

An R package providing high-quality datasets of Palmer Archipelago (Antarctica) penguin observations. It includes a simplified 'penguins' dataset and a 'penguins_raw' dataset, serving as a modern alternative to the iris dataset for data exploration, visualization, and teaching.

Tokens
996
Snippets
5
Records
6
Agent score
27%

What's inside palmerpenguins

  1. Access the palmerpenguins datasets

    main

    The package provides two datasets. After loading the library, you can access them using data(package = 'palmerpenguins') or by calling them directly if they are attached to the search path.

    • penguins: A simplified version of the data suitable for exploration and visualization. It contains 8 variables including species, island, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, sex, and year.
    • penguins_raw: The original dataset containing all variables and original names as downloaded.
    library(palmerpenguins)
    data(package = 'palmerpenguins')
    
    # View the simplified dataset
    head(penguins)
    
    # View the raw dataset
    head(penguins_raw)
  2. Understand the available datasets: penguins and penguins_raw

    main

    The package provides two primary datasets for exploration:

    1. penguins: A simplified version of the raw data, ideal for most data exploration and visualization tasks. Use ?penguins in R for detailed documentation.
    2. penguins_raw: The original dataset containing all variables and original names as downloaded. Use ?penguins_raw in R for detailed documentation.

    Both datasets include information on different penguin species collected from various islands in the Palmer Archipelago, Antarctica.

    library(palmerpenguins)
    
    # Access the simplified dataset
    head(penguins)
    
    # Access the raw dataset
    head(penguins_raw)
  3. Install palmerpenguins from CRAN or GitHub

    main

    You can install the stable version of the package from CRAN using install.packages(). Alternatively, if you need the development version, you can install it directly from GitHub using the remotes package.

    # Install released version from CRAN
    install.packages("palmerpenguins")
    
    # Install development version from GitHub
    # install.packages("remotes")
    remotes::install_github("allisonhorst/palmerpenguins")
  4. Summarize and visualize penguin data

    main

    The penguins dataset is designed for use with tidyverse for quick summarization and ggplot2 for visualization.

    To summarize data (e.g., counting species or calculating means), use dplyr verbs like count() and summarize(). To visualize, use ggplot2 to map variables like flipper_length_mm, body_mass_g, or bill_length_mm to aesthetics.

    library(tidyverse)
    library(palmerpenguins)
    
    # Summarize species counts
    penguins %>% 
      count(species)
    
    # Calculate mean for all numeric columns by species
    penguins %>% 
      group_by(species) %>% 
      summarize(across(where(is.numeric), mean, na.rm = TRUE))
    
    # Visualize relationship between flipper length and body mass
    ggplot(data = penguins, 
           aes(x = flipper_length_mm, y = body_mass_g)) +
      geom_point(aes(color = species, shape = species), size = 3, alpha = 0.8) +
      theme_minimal()