-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
184 lines (184 loc) · 5.21 KB
/
.Rhistory
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
devtools::document()
?devtools::document
library(devtools)
devtools::build()
install()
devtools::document()
devtools::check()
pjo_palettes
names(pjo_palettes)
palette(pjo_palettes$LightningThief)
nationalparkcolors::park_palette('Everglades')
test_pjo_palette <- function(name, n) {
pal <- pjo_palettes[[name]]
if (is.null(pal))
stop("Palette not found.")
if (missing(n)) {
n <- length(pal)
}
if (n > length(pal)) {
stop("Number of requested colors greater than what palette can offer")
}
out <- pal[1:n]
structure(out, class = "palette", name = name)
}
#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "Arial", col = "#32373D")
}
library(pjocolors)
names(pjo_palettes)
test_pjo_palette('LightningThief')
#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, family = "Arial", col = "grey30")
}
test_pjo_palette('LightningThief')
names(pjo_palettes)
test_pjo_palette('SeaOfMonsters')
test_pjo_palette('TitansCurse')
test_pjo_palette('BatOfTheLabyrinth')
names(pjo_palettes)
test_pjo_palette('LastOlympian')
#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, col = "grey30")
}
test_pjo_palette <- function(name, n) {
pal <- pjo_palettes[[name]]
if (is.null(pal))
stop("Palette not found.")
if (missing(n)) {
n <- length(pal)
}
if (n > length(pal)) {
stop("Number of requested colors greater than what palette can offer")
}
out <- pal[1:n]
structure(out, class = "palette", name = name)
}
test_pjo_palette('BatOfTheLabyrinth')
pal <- test_pjo_palette('BatOfTheLabyrinth')
pal
devtools::build()
devtools::install()
library(tidyverse)
theme_set(theme_minimal())
test_pal <- function(palette) {
# Function to see what color palette look like
# Data has 5 distinct categories for a fill/color aesthetic
transit <-
tribble(
~city, ~cash_fare_adult,
'Toronto', 3.25,
'Montreal', 3.50,
'Vancouver', 3.00,
'Ottawa', 3.60,
'Edmonton', 3.50,
)
# Plot data with palette
ggplot(transit, aes(city, cash_fare_adult)) +
geom_col(aes(fill = city), alpha = 0.8) +
labs(x = NULL, y = 'Adult Transit Fare') +
scale_y_continuous(labels = scales::label_dollar()) +
scale_fill_manual(values = palette, name = NULL) -> p
plot(p)
}
view_pjo_palette <- function(name, n) {
pal <- pjo_palettes[[name]]
if (is.null(pal))
stop("Palette not found.")
if (missing(n)) {
n <- length(pal)
}
if (n > length(pal)) {
stop("Number of requested colors greater than what palette can offer")
}
out <- pal[1:n]
structure(out, class = "palette", name = name)
}
#' @export
#' @importFrom graphics rect par image text
#' @importFrom grDevices rgb
print.palette <- function(x, ...) {
n <- length(x)
old <- par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(par(old))
image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
rect(0, 0.9, n + 1, 1.1, col = rgb(1, 1, 1, 0.8), border = NA)
text((n + 1) / 2, 1, labels = attr(x, "name"), cex = 1, col = "grey30")
}
pal <- view_pjo_palette('TheLightningThief', n = 5)
library(pjocolors)
pal <- view_pjo_palette('TheLightningThief', n = 5)
pal <- view_pjo_palette('LightningThief', n = 5)
# Plot data with palette
ggplot(transit, aes(city, cash_fare_adult)) +
geom_col(aes(fill = city), alpha = 0.8) +
labs(x = NULL, y = 'Adult Transit Fare') +
scale_y_continuous(labels = scales::label_dollar()) +
scale_fill_manual(values = palette, name = NULL)
transit <-
tribble(
~city, ~cash_fare_adult,
'Toronto', 3.25,
'Montreal', 3.50,
'Vancouver', 3.00,
'Ottawa', 3.60,
'Edmonton', 3.50,
)
# Plot data with palette
ggplot(transit, aes(city, cash_fare_adult)) +
geom_col(aes(fill = city), alpha = 0.8) +
labs(x = NULL, y = 'Adult Transit Fare') +
scale_y_continuous(labels = scales::label_dollar()) +
scale_fill_manual(values = palette, name = NULL)
pal
transit <-
tribble(
~city, ~cash_fare_adult,
'Toronto', 3.25,
'Montreal', 3.50,
'Vancouver', 3.00,
'Ottawa', 3.60,
'Edmonton', 3.50,
)
pal <- view_pjo_palette('LightningThief', n = 5)
# Plot data with palette
ggplot(transit, aes(city, cash_fare_adult)) +
geom_col(aes(fill = city), alpha = 0.8) +
labs(x = NULL, y = 'Adult Transit Fare') +
scale_y_continuous(labels = scales::label_dollar()) +
scale_fill_manual(values = pal, name = NULL)
?palette
require(graphics)
palette(rainbow(6))
palette(rainbow(6))
palette(rainbow(6))
?structure
?print.palette