-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
96 lines (66 loc) · 3.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: "ggDoubleHeat"
output: github_document
---
<!-- badges: start -->
[![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)
<!-- badges: end -->
```{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.