2

I'm trying to insert hockey pucks into my ggplot. On font awesome, I found a hockey puck icon. I was hoping that ggimage::geom_icon could import font awesome icons, but unfortunately it doesn't:

library(ggimage)

set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                icon = "hockey-puck")
ggplot(d, aes(x,y)) + geom_icon(aes(image=icon))
Error in download_url(path) : 
  Failed to download https://raw.githubusercontent.com/ionic-team/ionicons/master/src/svg/hockey-puck.svg (HTTP 404)

Does anyone know where to find icons. I know there is this online vignette, but it doesn't specify where ios-power', 'ios-wifi', 'ios-pie' come from.

1 Answers1

1

the ggimage::list.icon function uses a helper function which looks for png files. This is really not useful, as the icons are svg files. Below a modified version for future users.

list_images <- function (url, filetype = "svg") 
{
  x <- readLines(url)
  y <- x[grep(paste0("title=\"[a-zA-Z0-9\\-]+\\.", filetype), x)]
  sub(paste0(".*title=\"([a-zA-Z0-9\\-]+)\\.",filetype, ".*"), "\\1", y)
}

list_icon <- function(){
  list_images("https://github.com/ionic-team/ionicons/tree/master/src/svg")
}

head(list_icon(), 10)
#>  [1] "accessibility-outline" "accessibility-sharp"   "accessibility"        
#>  [4] "add-circle-outline"    "add-circle-sharp"      "add-circle"           
#>  [7] "add-outline"           "add-sharp"             "add"                  
#> [10] "airplane-outline"
tjebo
  • 21,977
  • 7
  • 58
  • 94