ggthemes

repository·main·Indexed 23 days ago

https://github.com/jrnold/ggthemes

A collection of extra geoms, scales, and themes for the ggplot2 package in R. It allows users to create plots that mimic the visual styles of various publications and software, including The Economist, Wall Street Journal, and Excel.

Tokens
591
Snippets
3
Records
3
Agent score
30%

What's inside ggthemes

  1. Apply ggthemes to ggplot2 objects

    main

    The ggthemes package provides extra geoms, scales, and themes for ggplot2. To use them, load both libraries and add the theme or scale functions to your ggplot object using the + operator.

    Example setup with mtcars data:

    library("ggplot2")
    library("ggthemes")
    
    mtcars2 <- within(mtcars, {
      vs <- factor(vs, labels = c("V-shaped", "Straight"))
      am <- factor(am, labels = c("Automatic", "Manual"))
      cyl  <- factor(cyl)
      gear <- factor(gear)
    })
    
    p1 <- ggplot(mtcars2) +
      geom_point(aes(x = wt, y = mpg, colour = gear)) +
      labs(
        title = "Fuel economy declines as weight increases",
        subtitle = "(1973-74)",
        caption = "Data from the 1974 Motor Trend US magazine.",
        x = "Weight (1000 lbs)",
        y = "Fuel economy (mpg)",
        colour = "Gears"
      )
    library("ggplot2")
    library("ggthemes")
  2. Install ggthemes from CRAN or GitHub

    main

    You can install the stable version of ggthemes from CRAN or the development version from GitHub using devtools.

    To install the stable version:

    install.packages('ggthemes', dependencies = TRUE)

    To install the development version from GitHub (requires devtools and installing ggplot2 from source):

    library("devtools")
    install_github(c("hadley/ggplot2", "jrnold/ggthemes"))
    install.packages('ggthemes', dependencies = TRUE)
  3. Available themes and scales in ggthemes

    main

    The following table lists the theme and scale combinations demonstrated in the package examples. Use these functions to change the visual style of your ggplot2 plots.

    | Theme Function | Scale Function | Notes | |---|---| sorry | | theme_calc() | scale_color_calc() | | | theme_clean() | | | | theme_economist() | scale_colour_economist() | | | theme_excel() | scale_colour_excel() | | | theme_excel_new() | scale_colour_excel_new() | | | theme_igray() | | | | theme_par() | | | | theme_fivethirtyeight() | | | | theme_few() | scale_colour_few() | | | theme_solarized() | scale_colour_solarized() | Use theme_solarized(light=FALSE) for dark mode | | theme_solid() | | | | theme_tufte() | | | | theme_stata() | | | | theme_wsj(base_size = 8) | scale_color_wsj() | base_size controls text size | | | scale_color_colorblind() | Colorblind friendly scale | | | scale_color_tableau() | Tableau color scale |

    p1 + theme_economist() + scale_colour_economist()