sfc_apply,sfc_nxn-method | R Documentation |
Apply to every unit in the sfc_nxn curve
## S4 method for signature 'sfc_nxn'
sfc_apply(p, depth = 1, fun = function(x) x)
p |
An |
depth |
An integer between 0 and |
fun |
A function of which the argument |
This function is mainly used to flip subunits on various levels on the curve, thus mainly on the Peano curve and the Meander curve. A depth of 0 corresponds to the complete curve. A depth of 1 corresponds to the nine first-level units, et al.
Currently, sfc_apply()
only works on curves with a single base pattern as the seed.
An sfc_nxn
object.
p = sfc_3x3_peano("I", level = 3)
# flip the global curve
draw_multiple_curves(
p,
sfc_apply(p, 0, sfc_flip_unit),
nrow = 1
)
# flip all the subunits on depth = 1
draw_multiple_curves(
p,
sfc_apply(p, 1, sfc_flip_unit),
nrow = 1
)
# flip all the subunits on depth = 2
draw_multiple_curves(
p,
sfc_apply(p, 2, sfc_flip_unit),
nrow = 1
)
# flip all level-1 patterns on the Peano curve to horizontal
# only works on the lowest subunit,
p2 = sfc_apply(p, 2, function(x) {
if(level1_unit_orientation(x) == "vertical") {
sfc_flip_unit(x)
} else {
x
}
})
# then on depth=1, only flip the unit with odd index
p3 = sfc_apply(p2, 1, function(x, i) {
if(i %% 2 == 1) {
sfc_flip_unit(x)
} else {
x
}
})
draw_multiple_curves(p2, p3, nrow = 1)
# flip all level-1 patterns to vertical
p3 = sfc_apply(p, 2, function(x) {
if(level1_unit_orientation(x) == "horizontal") {
sfc_flip_unit(x)
} else {
x
}
})
draw_multiple_curves(p, p3, nrow = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.