-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypoimg_geom_grob.Rmd
86 lines (71 loc) · 2.75 KB
/
hypoimg_geom_grob.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
---
title: "geom_grob()"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{geom_grob()}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
chunk_output_type: console
---
```{css, echo=FALSE}
img {
border: 0;
}
```
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
dev = "ragg_png"
)
options(warn = - 1) # suppress warnings in grid due to rotated grobs (for successful vignette building)
library("ragg")
library("hypoimg")
```
The **hypoimg** package implements a new geom: `geom_hypo_grob()`.
This geom provides a possibility to distribute grobs over different facets of a ggplot.
It needs a tibble that organizes the grobs according to the faceting levels.
This geom builds heavily on the answer by baptiste on the tidyverse github forum [issue 1399](https://github.com/tidyverse/ggplot2/issues/1399).
To the original answer, only the parameters height, width and angle have been added.
```{r geomGrob, out.width = "100%", fig.width = 11, fig.height = 6}
# Our color map
clr <- c(RColorBrewer::brewer.pal(5,'Oranges')[3],
RColorBrewer::brewer.pal(5,'Blues')[5])
# creating a list of grobs from single hamlet legend elements
grobs <- list(hypo_anno_single(species = 'indigo',
circle_fill = clr[2],
circle_lwd = 1,circle_color = 'black') %>%
ggplotGrob(),
hypo_anno_single(species = 'chlorurus',
circle_fill = clr[1],
circle_lwd = 1,circle_color = 'black') %>%
ggplotGrob())
# The tibbble that combines grobs, aesthetic and facetting levels
grob_list <- tibble(RUN = c('ind', 'chl'),
angle = c(30, -30),
height = c(.9,.7),
grob = grobs)
# some fake data set
test_df <- tibble(x = rep(1:10, 2),
y = rnorm(20),
RUN = rep(c('ind', 'chl'), each = 10))
# Using geom_hypo_grob() to distribute the grobs
ggplot()+
facet_grid(RUN~.)+
geom_hypo_grob(data = grob_list,
aes(grob = grob, angle = angle, height = height),
inherit.aes = FALSE, x = .85, y = 0.5)+
geom_line(data = test_df,
aes(x = x, y = y, color = RUN), size = 2)+
geom_point(data = test_df,
aes(x = x, y = y, fill = RUN), shape = 21, size = 4)+
scale_x_continuous(expand = c(0, 0), limits = c(0, 14))+
scale_fill_manual(values = clr)+
scale_color_manual(values = clr)+
theme(legend.position = 'bottom')
```
---------------------------------
```{r, echo = FALSE, fig.asp = 1, out.height = "150pt", out.width = "150pt", fig.align = "center"}
grImport2::grid.picture(grImport2::readPicture("logo.c.svg"))
```