approx_degrees | R Documentation |
Interpolation for degree angles
approx_degrees(
h1,
h2,
h = NULL,
preset = "custom",
direction = 1,
digits = 10,
verbose = FALSE,
...
)
h1 |
|
h2 |
|
h |
|
digits |
|
... |
additional arguments are ignored. |
This function is analogous to stats::approx()
except for
the special case of degree angles. In this case, degrees
are confined to the range [0, 360]
, and angle are smoothly
interpolated around the degrees of a circle.
This function should work properly even when the degree angles
in h2
are reversed, or offset. The only implicit requirement
is that angles in "from" should be mapped to one and only one
angle in "to".
Other colorjam hue warp:
add_colorjam_preset()
,
add_colorjam_step()
,
adjust_hue_warp()
,
colorjam_presets()
,
colorjam_steps()
,
display_degrees()
,
h2hw()
,
h2hwOptions()
,
hcl_to_hsl_hue()
,
hsl_to_hcl_hue()
,
hw2h()
,
mean_angle()
,
plot_colorjam_preset()
,
remap_colorjam_preset()
,
validate_colorjam_preset()
h_colors <- jamba::getColorRamp(c("white", "firebrick"), n=35, trimRamp=c(1, 0));
h1 <- c(12.2, 27.3, 47.0, 66.5, 85.9, 106.3, 131.7,
223.1, 263.2, 277.2, 307.7, 345.3, 372.2)
h2 <- seq(from=0, to=360, length.out=13)
h_from <- seq(from=0, to=360, length.out=36)[-36]
h_to <- approx_degrees(h1, h2, h_from)
par("mfrow"=c(2, 2))
display_degrees(h_from, col=h_colors)
display_degrees(h_to, col=h_colors)
plot(h_from, h_to, pch=20, col=h_colors)
par("mfrow"=c(1, 1))
h2 <- c(12.2, 27.3, 47.0, 66.5, 85.9, 106.3, 131.7,
223.1, 263.2, 277.2, 307.7, 345.3, 372.2)
h1 <- seq(from=0, to=360, length.out=13)
h_from <- seq(from=0, to=360, length.out=36)[-36]
h_to2 <- approx_degrees(h2, h1, h_from)
par("mfrow"=c(2, 2))
display_degrees(h_from, col=h_colors)
display_degrees(h_to2, col=h_colors)
plot(h_from, h_to2, pch=20, col=h_colors)
par("mfrow"=c(1, 1))
h1 <- c(12.2, 27.3, 47.0, 66.5, 85.9, 106.3, 131.7,
223.1, 263.2, 277.2, 307.7, 345.3, 372.2)
h2 <- rev((seq(from=0, to=360, length.out=13))[c(9:12,1:9)])
h_from <- seq(from=0, to=360, length.out=36)[-36]
h_to <- approx_degrees(h1, h2, h_from)
par("mfrow"=c(2, 2))
display_degrees(h_from, col=h_colors)
display_degrees(h_to, col=h_colors)
plot(h_from, h_to, pch=20, col=h_colors)
par("mfrow"=c(1, 1))
# apply no transform
approx_degrees(h1=0, h2=0, h=c(0, 90, 180, 270))
# apply 180 degree transform
approx_degrees(h1=0, h2=180, h=c(0, 90, 180, 270))
approx_degrees(h1=180, h2=0, h=c(0, 90, 180, 270))
# flip the direction
approx_degrees(h1=c(1, 360), h2=c(359, 0), h=c(0, 90, 180, 270))
approx_degrees(h1=c(1, 360), h2=c(359, 0)+90, h=c(0, 90, 180, 270))
approx_degrees(h1=c(1, 360)+90, h2=c(359, 0), h=c(0, 90, 180, 270))
# verify reverse h2 with break across 0-360
seq1 <- seq(from=0, to=330, by=30)
seq2 <- (rev(seq1) + 120) %% 360
seq_out <- seq(from=0, to=350, by=10);
approx_out <- approx_degrees(h1=seq1, h2=seq2, h=seq_out, verbose=TRUE)
plot(seq1, seq2, pch=20, col="blue", asp=1, ylim=c(0, 360))
points(seq_out, approx_out, col="red", add=TRUE, cex=2)
# verify forward h2 with break across 0-360
seq1 <- seq(from=0, to=330, by=30)
seq2 <- (seq1 + 120) %% 360
seq_out <- seq(from=0, to=350, by=10);
approx_out <- approx_degrees(h1=seq1, h2=seq2, h=seq_out, verbose=TRUE)
plot(seq1, seq2, pch=20, col="blue", asp=1, ylim=c(0, 360))
points(seq_out, approx_out, col="red", add=TRUE, cex=2)
new_h1h2 <- adjust_hue_warp(preset="dichromat", h2_shift=15, reverse_h2=TRUE)
hseq <- seq(from=0, to=350, by=15);
approx_degrees(h2=new_h1h2$h1, h1=new_h1h2$h2, h=hseq, verbose=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.