ezplot

Coverage status CRAN status Travis build status CRAN RStudio mirror downloads Total CRAN downloads

Installation

You can install the released version of ezplot from CRAN with:

install.packages("ezplot")

… or the latest stable Github version with:

devtools::install_github("wkostelecki/ezplot")

Overview

ezplot provides high-level wrapper functions for common chart types with reduced typing and easy faceting. e.g.: - line_plot() - area_plot() - bar_plot() - tile_plot() - waterfall_plot() - side_plot() - secondary_plot()

Usage

library(ezplot)
library(tsibbledata)

line_plot

line_plot(ansett, x = "Week", y = "Passengers") # weekly aggregate "Passengers"

line_plot(ansett, x = "Week", y = "Passengers", group = "Airports") # adds "Airports" grouping
line_plot(ansett, x = "Week", y = "Passengers", group = "Airports", facet_x = "Class") # facet by "Class"
# with group and two facets:
line_plot(ansett, x = "Week",
          y = c("Weekly Passengers" = "Passengers"),
          group = "substr(Airports, 5, 7)",
          facet_x = "substr(Airports, 1, 3)", facet_y = "Class",
          facet_scales = "free_y")

area_plot (stacked area)

area_plot(ansett, x = "Week", y = "Passengers")
area_plot(ansett, x = "Week", y = c("Weekly Passengers" = "Passengers"), "Class")

area_plot(ansett, "Week",
          y = c("Weekly Passengers" = "Passengers"),
          group = "substr(Airports, 5, 7)",
          facet_x = "substr(Airports, 1, 3)", facet_y = "Class",
          facet_scales = "free_y")

bar_plot

bar_plot(ansett, x = "lubridate::year(Week)", y = "Passengers")
bar_plot(ansett, 
         x = "lubridate::year(Week)",
         y = c("Yearly Passengers" = "Passengers"),
         "Class")

tile_plot

nyc_bikes %>%
  mutate(duration = as.numeric(stop_time - start_time)) %>%
  filter(between(duration, 0, 16)) %>%
  tile_plot(c("Trip Start (Hour of Day)" = "lubridate::hour(start_time) + 0.5"),
            c("Ride Duration (min)" = "duration - duration %% 2 + 1"))

waterfall_plot

waterfall_plot(aus_retail,
               "lubridate::year(Month)",
               "Turnover", 
               "sub(' Territory', '\nTerritory', State)", 
               rotate_xlabel = TRUE)

side_plot

side_plot(PBS, 
          "paste(Concession, Type, sep = ' - ')", 
          c("Scripts", "Cost", "Average Cost" = "~ Cost / Scripts"))

secondary_plot

Plot with secondary y-axis.

secondary_plot(pelt, "Year",
               c("Hare Population" = "Hare"), c("Lynx Population" = "Lynx"),
               size = 10,
               ylim1 = c(0, 160e3),
               ylim2 = c(0, 80e3))