Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FontAwesome glyphs not exporting using ggplot #55

Closed
cjtulley opened this issue Dec 12, 2018 · 1 comment
Closed

FontAwesome glyphs not exporting using ggplot #55

cjtulley opened this issue Dec 12, 2018 · 1 comment

Comments

@cjtulley
Copy link

Hello, I'm having an issue where I can generate a waffle plot in RStudio, but it won't export with the glyphs included. On attempting to export the plots with ggplot's "ggsave", I am having the same issue that other users have reported, where the icon displays a colored dot instead of the glyph. I'm trying to reproduce a set of graphs using someone else's code. This is the error:

There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label),  ... :
  font family 'FontAwesome' not found, will use 'wqy-microhei' instead`

I've installed FontAwesome 4.7.0.ttf, reinstalled waffle from GitHub instead of Cran, and tried the following code options to import/force FA to be recognized:

#Load font
font_import(paths = dirname(fa_font), prompt = FALSE)
fonts()
## [1] "FontAwesome"
if (.Platform$OS.type == "windows") loadfonts("win")
#FontAwesome already registered with windowsFonts().
# [1] "FontAwesome"

extrafont::loadfonts(device="win")
system.file("fonts", package="waffle")
loadfonts(device = "win")

font_import(pattern = 'fontawesome-webfont.ttf')

# check that Font Awesome is imported
fonts()[grep("Awesome", fonts())]

#check that FA glyphs are available
fa_list()

Every attempt to verify that Font Awesome is loaded appears to confirm that it is working. It's obviously loaded and available in RStudio. I can save the plot from the RStudio plot window and the icons will be there. There's some sort of disconnect between waffle, ggplot, and Font Awesome.

This code works:

waffle(c(data), flip = FALSE, reverse = TRUE, pad = 0, use_glyph = "male", size = 0.5,
       colors = c("#e31a1c", "#fd8d3c", "#fecc5c", "#ffffb2")) + theme(legend.position="none")

This code produces the pngs with missing glyphs:

#
for (i in 1 : nrow(rawdata)) {
  ## create data for current level
  a <- as.integer(as.character(rawdata[i, 15]))
  b <- as.integer(as.character(rawdata[i, 16]))
  c <- as.integer(as.character(rawdata[i, 17]))
  d <- as.integer(as.character(rawdata[i, 18]))
  data <- c(a, b, c, d)
  
## plot waffle charts & save as PNG files.
#
  
waf <-waffle(data, flip = TRUE, reverse = TRUE, pad = 0, use_glyph = "male", size = 0.5,
              colors = c("#e31a1c", "#ff7f00", "#fdbf6f", "#ffeda0")) + theme(legend.position="none")
 
  ## create customized name
  filename <- paste0(rawdata$`GIS ID`[i],'.png')
  ggsave(filename, waf, dpi = 1500)
}

Any suggestions would be welcome. Thanks!

@cjtulley
Copy link
Author

Just wanted to add an update on this. The issue appears to have been caused from loading either the extrafontsdb or the emojifonts libraries. I was able to successfully run this again with only importing data.table, waffle, extrafont, and ggplot2. Hope this helps anyone else having a similar issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant