Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://pursuitofdatascience.github.io/ggDoubleHeat/

ggDoubleHeat: A heatmap-like visualization tool
https://pursuitofdatascience.github.io/ggDoubleHeat/

Last synced: 3 days ago
JSON representation

ggDoubleHeat: A heatmap-like visualization tool

Awesome Lists containing this project

README

        

---
title: "ggDoubleHeat"
output: github_document
---

[![R-CMD-check](https://github.com/PursuitOfDataScience/ggDoubleHeat/workflows/R-CMD-check/badge.svg)](https://github.com/PursuitOfDataScience/ggDoubleHeat/actions)
[![CRAN status](https://www.r-pkg.org/badges/version/ggDoubleHeat)](https://CRAN.R-project.org/package=ggDoubleHeat)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
warning = FALSE,
message = FALSE,
fig.path = "man/figures/README-")
```

The `ggDoubleHeat` package is a `ggplot2` extension that provides visualization for data from two different sources on a modified heat map. All functions from the package are named as `geom_heat_*()`. A regular heat map, which can be made by using `geom_tile()` from `ggplot2`, contains three dimensions (variables). `geom_heat_*()`, however, can express four dimensions of data on a single plot.

## Installation

Please install the released version of `ggDoubleHeat` from CRAN with:

``` r
install.packages("ggDoubleHeat")
```

Alternatively, you can install the latest development version from Github with:

``` r
# install.packages("devtools")
devtools::install_github("PursuitOfDataScience/ggDoubleHeat")
```

## Usage

For demonstration purposes, the built-in dataset `pitts_tg` is used to illustrate the basic usage of the package.

```{r}
library(ggDoubleHeat)
library(ggplot2)
pitts_tg
```

`pitts_tg` is a dataset that collects the 30-week period of COVID-related Google & Twitter incidence rate for 9 different categories from the Pittsburgh Metropolitan Statistical Area (MSA). For the complete information of the dataset, please type `?pitts_tg` on the console.

Let's start with `geom_heat_grid()`:

```{r}
ggplot(data = pitts_tg, aes(x = week, y = category)) +
geom_heat_grid(outside = Google, inside = Twitter) +
ggtitle("Pittsburgh Google & Twitter Incidence Rate (%) Comparison")
```

Now changing `geom_heat_grid()` to `geom_heat_circle()`:

```{r}
ggplot(data = pitts_tg, aes(x = week, y = category)) +
geom_heat_circle(outside = Google, inside = Twitter) +
ggtitle("Pittsburgh Google & Twitter Incidence Rate (%) Comparison")

```

Let's use `geom_heat_tri()`:

```{r}
ggplot(data = pitts_tg, aes(x = week, y = category)) +
geom_heat_tri(lower = Google, upper = Twitter) +
ggtitle("Pittsburgh Google & Twitter Incidence Rate (%) Comparison")
```

To make things a bit more colorful, the most popular emoji for a given week in a given category from the respective Pittsburgh Twitter daily sample files is rendered on each component of the heatgrid by using `ggtext`. The following code is commented, as it takes few minutes to generate. If you would like to run it, just simply uncomment the code. **But the generated heatgrid with emojis is attached below as an image**.

```{r fig.height = 8, fig.width = 15}
# install.packages("ggtext")
# library(ggtext)
#
# ggplot(data = pitts_tg, aes(x = week, y = category)) +
# geom_heat_grid(outside = Google, inside = Twitter) +
# # rendering emojis using "richtext"
# annotate("richtext", x = rep(c(1:30), 9), y = rep(1:9, each = 30),
# label = pitts_emojis, label.color = NA, fill = NA, size = 0.3) +
# ggtitle("Pittsburgh Google & Twitter Incidence Rate (%) Comparison")
```

![image](https://user-images.githubusercontent.com/54338793/153519943-24346494-11ec-41df-ba38-b17bc4272fa4.png)

Note: `pitts_emojis` is the Emoji metadata built in `ggDoubleHeat`. Another thing worth noting is that there are some grids not having Emoji, and the reason is that there is no Emoji Unicode in the Twitter sample file.