Giter Site home page Giter Site logo

emwthemes's Introduction

emwthemes personal package

Emma Marshall

emwthemes

R-CMD-check

This is a package for personal use.

Installation

You can install the development version of emwthemes from GitHub with:

# install.packages("devtools")
devtools::install_github("emmarshall/emwthemes")

Package functions

update_geom_fonts_em: Update font defaults for text geoms to use playful font Architects Daughter

add_logo: easily add logo to plot object

link_to_img: processes image from url for use with ggimage()

Fonts & Colors

See vignette.

Themes use two different color palette:

scales::show_col(emwthemes:::emw_pal(5))
scales::show_col(emwthemes:::dark_pal(5))
scales::show_col(emwthemes:::unl_pal(5))

Personal Color Palette (default for theme_emw())

Personal Scale colors

Personal Scale colors

Bright Color Palette (default for theme_emw_dark())

Bright Scale colors

Bright Scale colors

Discrete and Continuous Scale

scale_color_em: Discrete color & fill scales based on a bright palette

scale_fill_em: Discrete color & fill scales based on a bright palette

Scale functions

Examples

You can find the code for all the examples below in the “Examples” Vignette on the Package Website.

Examples

library(emwthemes)
#> Package fonts loaded. See `?load_pkg_fonts` for details.
library(ggplot2)
library(extrafont)
#> Registering fonts with R
library(survivoR)
library(stringr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tidyr)
loadfonts(quiet = TRUE)

line <- season_summary |> 
  filter(version == "US") |> 
  select(season, viewers_premiere, viewers_finale, viewers_reunion, viewers_mean)  |> 
  pivot_longer(cols = -season, names_to = "episode", values_to = "viewers") |> 
  mutate(
    episode = str_to_title(str_replace(episode, "viewers_", ""))
  ) |> 
  ggplot(aes(x = season, y = viewers, colour = episode)) +
  geom_line() +
  geom_point(size = 1.5) +
  labs(
    title = "Survivor viewers over the 40 seasons",
    subtitle = "Decline in viewership over the years",
    x = "Season",
    y = "Viewers (Millions)",
    colour = "Episode"
  ) +
  theme_em()

Example plot with theme_emw()

Example plot with theme_emw()

Dark Theme

line +
  theme_emw_dark()

Example plot with theme_emw_dark()

Example plot with theme_emw_dark()
line +

  theme_unl_dark()

Bar Charts

library(glue)
ssn <- 37
labels <- castaways  |> 
  filter(
    season == ssn,
    str_detect(result, "Sole|unner")
  ) |> 
  mutate(label = glue("{castaway} ({original_tribe})")) |> 
  select(label, castaway)
 
bar <- jury_votes |> 
  filter(season == ssn) |> 
  left_join(
    castaways |> 
      filter(season == ssn) |> 
      select(castaway, original_tribe),
    by = "castaway"
  ) |> 
  group_by(finalist, original_tribe) |> 
  summarise(votes = sum(vote)) |> 
  left_join(labels, by = c("finalist" = "castaway")) |> 
    ggplot(aes(x = label, y = votes, fill = original_tribe)) +
      geom_bar(stat = "identity", width = 0.5) +
      labs(
        x = "Finalist (original tribe)",
        y = "Votes",
        fill = "Original\ntribe",
        title = "David vs Goliath: Season 37 Final Tribal",
        subtitle = "Votes received by each finalist"
      ) +
  theme_emw(with.axis.line = TRUE) +
  scale_x_discrete(guide = guide_axis(n.dodge = 3))

Example plot with theme_emw()

Example plot with theme_emw()
bar +
  theme_emw_dark(with.axis.line = TRUE) 

Example plot with theme_emw_dark()

Example plot with theme_emw_dark()

Using theme_em() with Oswald font and md=TRUE

Alternate, more professional option with built in ability to use ggtext::markdown_elements

Using theme_em to print a scatter plot with width = 12 inches & height = 8 inches and the md = TRUE argument to use ggtext::element_markdown() instead of element_text() for text elements, in this case the subtitle:

line_md <- season_summary |> 
  filter(version == "US") |> 
  select(season, viewers_premiere, viewers_finale)  |> 
  pivot_longer(cols = -season, names_to = "episode", values_to = "viewers") |> 
  mutate(
    episode = str_to_title(str_replace(episode, "viewers_", ""))
  ) |> 
  ggplot(aes(x = season, y = viewers, colour = episode)) +
  geom_line() +
  labs(
    title = "Survivor viewers over the 40 seasons",
    subtitle = "Decline in <span style = 'color:#ff8281;'>viewership</span> over time",
    x = "Season",
    y = "Viewers (Millions)",
    color = "Episode"
  ) 
line_md +
  theme_em(md = TRUE) 
#> Warning: Removed 6 rows containing missing values or values outside the scale range
#> (`geom_line()`).

Example plot with theme_em()

Example plot with theme_em()
line_md +
  theme_em_dark(md = TRUE,
                with.line = TRUE) 
#> Warning: Removed 6 rows containing missing values or values outside the scale range
#> (`geom_line()`).

Example plot with theme_em_dark()

Example plot with theme_em_dark()

emwthemes's People

Contributors

emmarshall avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.