Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active September 26, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/4f33a397a4fbedb8bf00dca9c6a0d12a to your computer and use it in GitHub Desktop.
Save yutannihilation/4f33a397a4fbedb8bf00dca9c6a0d12a to your computer and use it in GitHub Desktop.
# https://github.com/GuangchuangYu/shadowtext/blob/master/vignettes/shadowtext.Rmd
library(ggplot2)
library(shadowtext)

random_text <- function(n=1, length=10) {
  d <- data.frame(n=1:n, length=length)
  sapply(1:nrow(d), function(i) {
    paste(sample(c(0:9, letters, LETTERS),
                 d$length[i], replace=TRUE),
          collapse="")
  })
}

n <- 10
set.seed(2017-10-27)
d <- data.frame(x = rnorm(n), y=rnorm(n),
                label = random_text(n),
                angle = sample(0:360, 10))
p <- ggplot(d, aes(x, y)) + xlim(-2, 2.2) + ylim(-2, 2.4)

# OK
p1 <- p + geom_shadowtext(aes(label=label, angle=angle), size=5)
p1

system("git clone https://github.com/GuangchuangYu/shadowtext")
devtools::check("shadowtext")
#> Updating shadowtext documentation
#> Loading shadowtext
#> Updating roxygen version in C:\Users\hiroaki-yutani\AppData\Local\Temp\RtmpuAT6gf\reprex43445fa05ab5\shadowtext/DESCRIPTION
#> Writing NAMESPACE
#> Writing NAMESPACE
#> Writing geom_shadowtext.Rd
#> Writing shadowtextGrob.Rd
#> Writing reexports.Rd
#> Setting env vars ---------------------------------------------------------
#> CFLAGS  : -Wall -pedantic
#> CXXFLAGS: -Wall -pedantic
#> Building shadowtext ------------------------------------------------------
#> "C:/PROGRA~1/R/R-35~1.1/bin/x64/R" --no-site-file --no-environ --no-save  \
#>   --no-restore --quiet CMD build  \
#>   "C:\Users\hiroaki-yutani\AppData\Local\Temp\RtmpuAT6gf\reprex43445fa05ab5\shadowtext"  \
#>   --no-resave-data --no-manual
#> 
#> Error: Command failed (1)

# Error
p2 <- p + geom_shadowtext(aes(label=label, angle=angle), size=5)
p2
#> Error in col[, rep(1, length(alpha)), drop = FALSE]: subscript out of bounds

# bg.color vs bg.colour ...?
p1$layers[[1]]$geom$default_aes
#> Aesthetic mapping: 
#> * `colour`     -> "white"
#> * `size`       -> 3.88
#> * `angle`      -> 0
#> * `hjust`      -> 0.5
#> * `vjust`      -> 0.5
#> * `alpha`      -> NA
#> * `family`     -> ""
#> * `fontface`   -> 1
#> * `lineheight` -> 1.2
#> * `bg.color`   -> "black"
#> * `bg.r`       -> 0.1
p2$layers[[1]]$geom$default_aes
#> Aesthetic mapping: 
#> * `colour`     -> "white"
#> * `size`       -> 3.88
#> * `angle`      -> 0
#> * `hjust`      -> 0.5
#> * `vjust`      -> 0.5
#> * `alpha`      -> NA
#> * `family`     -> ""
#> * `fontface`   -> 1
#> * `lineheight` -> 1.2
#> * `bg.colour`  -> "black"
#> * `bg.r`       -> 0.1

Created on 2018-09-27 by the reprex package (v0.2.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment