-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
269 lines (269 loc) · 7.01 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
as.color <- function(x, alpha){
#set color alpha, or default to 0.5
if(missing(alpha)){
alpha <- 0.5
}
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
#assign colors to input values
colvec <- rep(NA, length(x))
for(i in 1:length(numcols)){
colvec[x %in% numcols[i] ] <- colz[i]
}
return(colvec)
}
#simple data frame with factors
set.seed(12345) #make results reproducible
n <- 100
f <- 5
x <- sort(rnorm(n, mean = 0, sd = 50)) + rnorm(n, mean = 0, sd = 30)
fact <- rep(letters[1:5], each=n/f)
#call to as.color, with char vector
colz <- as.color(fact, alpha = 1)
plotx <- as.integer(as.factor(fact))
plot( jitter(plotx), x, col=colz, pch=19)
#call to as.color, with char vector
colz <- as.color(fact, alpha = 0.5)
plotx <- as.integer(as.factor(fact))
plot( jitter(plotx), x, col=colz, pch=19)
colz
x
x
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
alpha <- 0.5
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
colz
i <- 1
i <- 1
numcols
numcols[i]
fact <- rep(letters[1:5], each=n/f)
fact
fact
fact
x <- fact
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
x
length(numcols)
numcols[i]
x
x %in% numcols[i]
x
numcols[i]
x %in% numcols[i]
tibble(
numcols ,
x
)
library(tidyverse)
as_tibble
as_tibble(
numcols ,
x
)
tibble(
numcols ,
x
)
tibble(
numcols = numcols,
x = x
)
numcols
x
colvec
colz
tibble(
numcols = numcols,
colz = colz
)
tibble(
x = numcols,
colz = colz
) %>%
left_join()
tibble(
x = numcols,
colz = colz
)
x
tibble(x = x)
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = ",")
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = "x")
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = "x") %>%
pull(colz)
as.color <- function(x, alpha = 0.5){
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = "x") %>%
pull(colz)
}
#simple data frame with factors
set.seed(12345) #make results reproducible
n <- 100
f <- 5
x <- sort(rnorm(n, mean = 0, sd = 50)) + rnorm(n, mean = 0, sd = 30)
fact <- rep(letters[1:5], each=n/f)
#call to as.color, with char vector
colz <- as.color(fact, alpha = 0.5)
plotx <- as.integer(as.factor(fact))
plot(jitter(plotx), x, col=colz, pch=19)
library(tidyverse)
as.color <- function(x, alpha = 0.5){
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = "x") %>%
pull(colz)
}
#simple data frame with factors
set.seed(12345) #make results reproducible
n <- 100
f <- 5
x <- sort(rnorm(n, mean = 0, sd = 50)) + rnorm(n, mean = 0, sd = 30)
fact <- rep(letters[1:5], each=n/f)
#call to as.color, with char vector
colz <- as.color(fact, alpha = 0.5)
plotx <- as.integer(as.factor(fact))
plot(jitter(plotx), x, col=colz, pch=19)
x
library(tidyverse)
as.color <- function(x, alpha = 0.5){
#get the number of colors needed
numcols <- unique(x)
colseqR <- seq(0, 1, length.out=255)
colseqG <- seq(0, 1, length.out=255)
colseqB <- seq(0, 1, length.out=255)
#check for number of input colors
if( length(numcols) > 255){
warning("The input vector requires a large number of colors,
some colors will be recycled, or appear extremely similar visually.")
}
#create colors
r <- sample(colseqR, length(numcols), replace = T)
g <- sample(colseqG, length(numcols), replace = T)
b <- sample(colseqB, length(numcols), replace = T)
colz <- rgb(red = r, green = g, blue = b, alpha = alpha)
tibble(
x = numcols,
colz = colz
) %>%
left_join(tibble(x = x), ., by = "x") %>%
pull(colz)
}
#simple data frame with factors
set.seed(12345) #make results reproducible
n <- 100
f <- 5
x <- sort(rnorm(n, mean = 0, sd = 50)) + rnorm(n, mean = 0, sd = 30)
fact <- rep(letters[1:5], each=n/f)
fact
#call to as.color, with char vector
colz <- as.color(fact, alpha = 0.5)
plotx <- as.integer(as.factor(fact))
plot(jitter(plotx), x, col=colz, pch=19)
plotx
plot(jitter(plotx), x, col=colz, pch=19)
plot(jitter(plotx), x, col=colz, pch=19, axes = F)
plot(jitter(plotx), x, col=colz, pch=19, xaxt = F)
plot(jitter(plotx), x, col=colz, pch=19, xax = F)
plot(jitter(plotx), x, col=colz, pch=19, xaxt = "none")
axis(side = 1, at = plotx, labels = fact)
library(as.color)
devtools::document(".")
devtools::install(".")
devtools::document("")
devtools::document(".")
devtools::install(".")
devtools::document(".")
devtools::install(".")