Closed rpruim closed 4 years ago
Proof of concept:
suppressPackageStartupMessages(library(ggformula))
KF <-
mosaicData::KidsFeet %>%
set_labels(
list(
length = 'foot length (cm)',
width = 'foot width (cm)',
birthmonth = 'birth month',
birthyear = 'birth year',
biggerfoot = 'bigger foot',
domhand = 'dominant hand'
)
)
KF %>%
gf_point(length ~ width, color = ~ domhand)
get_labels(KF)
#> $name
#> NULL
#>
#> $birthmonth
#> [1] "birth month"
#>
#> $birthyear
#> [1] "birth year"
#>
#> $length
#> [1] "foot length (cm)"
#>
#> $width
#> [1] "foot width (cm)"
#>
#> $sex
#> NULL
#>
#> $biggerfoot
#> [1] "bigger foot"
#>
#> $domhand
#> [1] "dominant hand"
mosaicData::KidsFeet %>% gf_point(width ~ length) %>%
gf_relabel(list(width = "width of foot", length = "length of foot"))
Created on 2020-07-08 by the reprex package (v0.3.0)
This has been refactored to reexport some functions from the {labelled} package instead of rolling my own.
Some packages like {expss} and {Hmisc} support labels that are different from variable names. This gives the best of both worlds: short syntactic names for coding and longer, expressive names for plotting and other purposes.
{expss} does this by adding a label attribute to the vectors in a data frame. These labels can be extracted and used in place of the variable names as default labels.
By extending the class of a ggplot produced with ggformula, we can have these extended labels used by default when a plot is printed.
Plan:
get_labels()
for extracting labels from objectsset_labels()
for adding a label (so users don't have to useattr()
), much likesetNames()
gf_relabel()
for manual relabeling