-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME.Rmd
119 lines (90 loc) · 3.29 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# hexagon <img src="man/figures/logo.png" width="160px" align="right" />
<!-- [](https://travis-ci.org/mkearney/hexagon)
[](https://cran.r-project.org/package=hexagon)
[](https://codecov.io/gh/mkearney/hexagon?branch=master)

 -->
[](https://www.tidyverse.org/lifecycle/#experimental)
R package for creating hexagon shaped xy data frames.
## Installation
To get the current development version from Github:
```{r, eval=FALSE}
## install devtools package if it's not already
if (!requireNamespace("devtools", quietly = TRUE)) {
install.packages("devtools")
}
## install dev version of hexagon from github
devtools::install_github("mkearney/hexagon")
## load rtweet package
library(hexagon)
```
## Usage
```{r, eval=FALSE}
## create hexagon xy data frame using argument defaults
hex1 <- hexdf()
## plot outline of hexagon
with(hex1, plot(x, y, type = "l"))
```
<p align="center"><img src="tools/readme/plot1.png" > </p
```{r, eval=FALSE}
## create larger hexagon to the lower right with a different midpoint
hex2 <- hexdf(2, mid = c(2.5, -2))
## load ggplot2
library(ggplot2)
## plot both hex1 and hex2 objects using ggplot2
ggplot(hex1, aes(x, y)) +
geom_polygon(fill = "blue") +
geom_polygon(data = hex2, fill = "red")
```
<p align="center"><img src="tools/readme/plot2.png" > </p
### Example
Create a package sticker
```{r fig.height=2.0, fig.width=1.73, eval=FALSE}
## generate some data to plot
n <- 43
den <- ceiling(n / 5)
x <- seq(-.525, .465, length.out = n) + rep(c(-.005, .005), ceiling(n/2))[1:n]
y <- seq(-.1, .1, length.out = ceiling(n / den))
y <- rep(c(y, rev(y)), ceiling(n / den))[1:n] + seq(.0, .45, length.out = n)
z <- c(rep("a", ceiling(n / den)), rep("b", ceiling(n / den)))
z <- rep(z, ceiling(n / den))[1:n]
pts <- data.frame(x, y, z)
## create base plot
p_ <- ggplot(hex1, aes(x, y)) +
geom_polygon(fill = "#114466", colour = "#001030", size = 1) +
geom_point(data = pts, aes(fill = z, colour = z), shape = 21, size = 1.75) +
scale_fill_manual(values = c("#8CFF00", "#cc00ff")) +
scale_colour_manual(values = c("#0A2200", "#110033")) +
annotate("text", 0, -.36, label = "hexagon",
colour = "white", size = 8, fontface = "bold") +
coord_fixed(ratio = 1, expand = TRUE) +
coord_cartesian(xlim = range(hex1$x), ylim = range(hex1$y)) +
theme_void()
## adjust margin to maximize sticker
t <- 6
r <- 5
b <- 9
l <- 8
p <- p_ +
theme(legend.position = "none",
plot.margin = margin(-t, -r, -b, -l, unit = "pt"))
#view plot in device
p
## save plot with sticker dimensions
#ggsave("hexagon-logo.png", p, width = 1.73, height = 2,
# units = "in", bg = "transparent")
```
<p align="center"><img width="150px" src="tools/readme/dots-sticker.png" > </p>