knitr::opts_chunk$set(
  collapse = TRUE,
  message = FALSE,
  warning = FALSE,
  comment = "#>",
  # cache.path = "man/README",
  fig.path = "man/README/README-"
)
viz_void <- ggplot2::ggplot() + ggplot2::theme_void()

dir_logo <- file.path("inst", "figures")
if(!exists(dir_logo)) {
  dir.create(dir_logo, recursive = TRUE)
}
path_logo <- file.path(dir_logo, paste0("logo.png"))
hexSticker::sticker(
  subplot = viz_void,
  package = "teplot",
  filename = path_logo,
  p_y = 1.0,
  p_color = "black",
  # p_family = "sans",
  p_size = 40,
  h_size = 1.5,
  h_color = "black",
  h_fill = "yellow"
)
logo <- magick::image_read(path_logo)
magick::image_write(magick::image_scale(logo, "120"), path = path_logo)

tetext

Introduction

This package containts functions that I often use.

Installation

devtools::install_github("tonyelhabr/teplot").

Notes

Here is a list of all functions in the package.

library("teplot")
ls("package:teplot")
# sprintf("Code coverage: %f", covr::package_coverage())

Examples

theme_te*() and te_colors

Here are some examples showing my custom theme and color palette.

library("teplot")
library("ggplot2")
library("datasets")

viz_cars <-
  ggplot(data = mtcars, aes(x = wt, y = mpg, color = factor(gear))) +
  geom_point(size = 2) +
  geom_smooth(method = "lm", se = FALSE, size = 2)
# viz_cars + theme_grey()
viz_cars +
  teplot::scale_color_te() +
  teplot::theme_te() +
  labs(title = "Yet another `mtcars` Example",
      subtitle = "Just showing off the custom theme.",
      caption = "And the custom colors.")

viz_cars_facet <-
  viz_cars +
  facet_wrap( ~ am, scales = "free")
# viz_cars_facet + theme_grey()
viz_cars_facet +
  teplot::scale_color_te() +
  teplot::theme_te_facet() +
  labs(title = "Similar to the Previous Example, but Facetted",
       subtitle = "The panels are given borders with this version of the theme (for facets)",
       caption = "Also, this shows off the strip text.")

viz_diamonds <-
  ggplot(data = diamonds, aes(x = clarity, fill = color)) +
  geom_bar()
# viz_diamonds + theme_grey()
viz_diamonds +
  teplot::scale_fill_te() +
  teplot::theme_te_dx() +
  labs(title = "How about them `diamonds`?",
       subtitle = "Note that the major vertical gridlines are removed with this theme.",
       caption = "Also, this shows off more of the range of colors in the custom palette.")

viz_diamonds_facet <-
  viz_diamonds +
  facet_wrap( ~ cut, scales = "free")

# viz_diamonds_facet + theme_grey()
viz_diamonds_facet +
  teplot::scale_fill_te() +
  teplot::theme_te_facet_dx() +
  labs(title = "`diamond`, Facetted",
       subtitle = "This version of the theme combines the modifications of the `_facet` and `_dx` versions.",
       caption = "The vibrant colors still 'pop' off the page, even with a facetted plot.")

# viz_diamonds_facet + theme_grey()
# viz_iris + teplot::scale_fill_te(palette = "cool", discrete = FALSE) + teplot::theme_te()
# viz_iris <-
#   ggplot(data = iris, aes(
#     x = ceiling(Sepal.Length),
#     y = ceiling(Sepal.Width),
#     fill = Petal.Length
#   )) +
#   geom_tile() +
#   viz_labs

Here are some examples showing the map functions.

teplot::create_map_state(state = "texas", show_county = FALSE) +
  teplot::theme_map() +
  labs(title = "Texas", 
       subtitle = "Is a Big State",
       caption = "And it's more urban than most tourists probably realize.")
teplot::create_map_base(state = "texas")

(Credit to https://journal.r-project.org/archive/2013-1/kahle-wickham.pdf for the data for the following example.)

library("ggmap")
crime <- ggmap::crime
ggmap_stamen_tx <- teplot::ggmap_stamen_tx

ggmap_stamen_tx +
  geom_point(data = crime, aes(x = lon, y = lat), color = "red", size = 1)

(Credit to https://mgimond.github.io/Spatial/interpolation-in-r.html for the data for the following example.)

library("tmap")
spdf_tx_precip <- teplot::spdf_tx_precip
spdf_tx <- teplot::spdf_tx
tmap::tm_shape(spdf_tx) +
  tmap::tm_polygons(col = "white", alpha = 0) +
  tmap::tm_shape(spdf_tx_precip) +
  tmap::tm_dots(
    col = "Precip_in",
    # palette = "RdBu",
    auto.palette.mapping = FALSE,
    title = "Sampled precipitation \n(in inches)",
    size = 0.7
  )


tonyelhabr/teplot documentation built on May 26, 2019, 5:33 a.m.