Giter Site home page Giter Site logo

yixuan / showtext Goto Github PK

View Code? Open in Web Editor NEW
475.0 19.0 38.0 4.89 MB

Using Fonts More Easily in R Graphs

Home Page: http://cran.r-project.org/web/packages/showtext/index.html

R 25.74% C 53.68% Makefile 0.32% TeX 15.74% M4 4.48% Shell 0.04%
font graphics r-graphics graphics-device

showtext's Introduction

showtextshowtext

What's this package all about?

showtext makes it easy to use various types of fonts (TrueType, OpenType, Type 1, web fonts, etc.) in R plots. The motivation to develop this package is that using non-standard fonts in R plots (especially for PDF device) is not straightforward, for example, when creating PDF with Chinese characters. This is because most of the standard fonts used by pdf() do not contain Chinese character glyphs, and users could hardly use system fonts in R.

The extrafont package developed by Winston Chang is one nice solution to this problem, which mainly focuses on using TrueType fonts (.ttf) in PDF graphics device. Now showtext is able to support more font formats and more graphics devices, and avoids using external software such as Ghostscript.

A quick example

library(showtext)
## Loading Google fonts (https://fonts.google.com/)
font_add_google("Gochi Hand", "gochi")
font_add_google("Schoolbell", "bell")
font_add_google("Covered By Your Grace", "grace")
font_add_google("Rock Salt", "rock")

## Automatically use showtext to render text for future devices
showtext_auto()

## Tell showtext the resolution of the device,
## only needed for bitmap graphics. Default is 96
showtext_opts(dpi = 96)

set.seed(123)
x = rnorm(10)
y = 1 + x + rnorm(10, sd = 0.2)
y[1] = 5
mod = lm(y ~ x)

op = par(cex.lab = 2, cex.axis = 1.5, cex.main = 2)
plot(x, y, pch = 16, col = "steelblue",
     xlab = "X variable", ylab = "Y variable", family = "gochi")
grid()
title("Draw Plots Before You Fit A Regression", family = "bell")
text(-0.5, 4.5, "This is the outlier", cex = 2, col = "steelblue",
     family = "grace")
abline(coef(mod))
abline(1, 1, col = "red")
par(family = "rock")
text(1, 1, expression(paste("True model: ", y == x + 1)),
     cex = 1.5, col = "red", srt = 20)
text(0, 2, expression(paste("OLS: ", hat(y) == 0.79 * x + 1.49)),
     cex = 1.5, srt = 15)
legend("topright", legend = c("Truth", "OLS"), col = c("red", "black"), lty = 1)

par(op)
quick_example

In this example we first load some fonts that are available online through Google Fonts, and then tell R to render text using showtext by calling the showtext_auto() function. All the remaining part is exactly the same as the usual plotting commands.

This example should work on most graphics devices, including pdf(), png(), postscript(), and on-screen devices such as windows() on Windows and x11() on Linux.

How showtext works

Let me first explain a little bit how pdf() works.

To my best knowledge, the default PDF device in R does not "draw" the text, but actually "describes" the text in the PDF file. That is to say, instead of drawing lines and curves of the actual glyph, it only embeds information about the text, for example what characters it has, which font it uses, etc.

However, the text with declared font may be displayed differently in different OS, which means that the appearance of graph created by pdf() is system dependent. If you unfortunately do not have the declared font in your system, you may not be able to see the text correctly at all.

In comparison, showtext package tries to solve this problem by converting text into color-filled polygonal outlines (for vector graphics) or raster images (for bitmap and on-screen graphics), thus having the same appearance under all platforms. People who view this graph do not need to install the font that creates the graph. It provides convenience to both graph makers and graph viewers.

More importantly, showtext can use system font files, so you can show text in the graph with your favourite font face, as long as it is supported by FreeType. See section Loading fonts below.

The usage

To create a graph using a specified font, you simply do the following:

  • (*) Load the font to be used by showtext
  • Open the graphics device
  • (*) Claim that you want to use showtext to draw the text
  • Plot
  • Close the device

Only the steps marked with (*) are new. If you want to use showtext globally, you can call the function showtext_auto() once, and then all the devices after that will automatically use showtext to render text, as the example in the beginning shows.

If you want to have finer control on which part of the code should use showtext, functions showtext_begin() and showtext_end() will help. Only plotting functions enclosed by this pair of calls will use showtext, and others not. For example, to change the title font only, we can do:

library(showtext)
font_add_google("Schoolbell", "bell")

## By default the automatic call of showtext is disabled
## You can manually turn it off using the line below
## showtext_auto(enable = FALSE)

## To use showtext_begin() and showtext_end() you need to
## explicitly open a graphics device
png("demo.png", 700, 600, res = 96)
set.seed(123)
x = rnorm(10)
y = 1 + x + rnorm(10, sd = 0.2)
y[1] = 5
mod = lm(y ~ x)

op = par(cex.lab = 1.5, cex.axis = 1.5, cex.main = 2)
plot(x, y, pch = 16, col = "steelblue",
     xlab = "X variable", ylab = "Y variable")
grid()

## Use showtext only for this part
showtext_begin()
title("Draw Plots Before You Fit A Regression", family = "bell")
showtext_end()

text(-0.5, 4.5, "This is the outlier", cex = 2, col = "steelblue")
abline(coef(mod))
abline(1, 1, col = "red")
text(1, 1, expression(paste("True model: ", y == x + 1)),
     cex = 1.5, col = "red", srt = 20)
text(0, 2, expression(paste("OLS: ", hat(y) == 0.79 * x + 1.49)),
     cex = 1.5, srt = 15)
legend("topright", legend = c("Truth", "OLS"), col = c("red", "black"), lty = 1)

par(op)
dev.off()
demo-2

Loading fonts

Loading font is actually done by package sysfonts.

The easy way to load font into showtext is by calling font_add(family, regular), where family is the name that you assign to that font (so that later you can call par(family = ...) to use this font in plotting), and regular is the path to the font file. That is to say, only knowing the "font name" is not enough, since they are usually system dependent. On the contrary, font file is the entity that actually provides the character glyphs.

Usually the font files are located in some "standard" directories in the system (for example on Windows it is typically C:\Windows\Fonts). You can use font_paths() to check the current search path or add a new one, and use font_files() to list available font files in the search path. font_files() also lists some other useful information, for example the family name that you usually use to specify a font, and the font face for different variants. Below is an example to show the results on my machine:

head(font_files())

##                     path                           file               family
## 1 ***/.local/share/fonts            Flavors-Regular.ttf              Flavors
## 2 ***/.local/share/fonts FrederickatheGreat-Regular.ttf Fredericka the Great
## 3 ***/.local/share/fonts           GandhiSerif-Bold.otf         Gandhi Serif
## 4 ***/.local/share/fonts     GandhiSerif-BoldItalic.otf         Gandhi Serif
## 5 ***/.local/share/fonts         GandhiSerif-Italic.otf         Gandhi Serif
## 6 ***/.local/share/fonts        GandhiSerif-Regular.otf         Gandhi Serif
##
##          face       version                    ps_name
## 1     Regular Version 1.001            Flavors-Regular
## 2     Regular Version 1.001 FrederickatheGreat-Regular
## 3        Bold Version 1.001           GandhiSerif-Bold
## 4 Bold Italic Version 1.001     GandhiSerif-BoldItalic
## 5      Italic Version 1.001         GandhiSerif-Italic
## 6     Regular Version 1.001        GandhiSerif-Regular

And the code below demonstrates how to load and use system fonts on Windows:

library(showtext)
## Add fonts that are available on Windows
font_add("heiti", "simhei.ttf")
font_add("constan", "constan.ttf", italic = "constani.ttf")

library(ggplot2)
p = ggplot(NULL, aes(x = 1, y = 1)) + ylim(0.8, 1.2) +
    theme(axis.title = element_blank(), axis.ticks = element_blank(),
          axis.text = element_blank()) +
    annotate("text", 1, 1.1, family = "heiti", size = 15,
             label = "\u4F60\u597D\uFF0C\u4E16\u754C") +
    annotate("text", 1, 0.9, label = 'Chinese for "Hello, world!"',
             family = "constan", fontface = "italic", size = 12)

## Automatically use showtext for new devices
showtext_auto()

## On-screen device
x11()
print(p)
dev.off()

## PDF device
pdf("showtext-example-3.pdf", 7, 4)
print(p)
dev.off()

## PNG device
ggsave("showtext-example-4.png", width = 7, height = 4, dpi = 96)

## Turn off if no longer needed
showtext_auto(FALSE)
example1

For other OS, you may not have the simhei.ttf font file, but there is no difficulty in using something else. At present font_add() supports TrueType fonts(*.ttf/*.ttc) and OpenType fonts(*.otf), and adding new font type is trivial as long as FreeType supports it.

Also, there are many free fonts available and accessible on the web, for instance the Google Fonts project (https://fonts.google.com/). sysfonts provides an interface to automatically download and register those fonts through the function font_add_google(), as the example below shows.

library(showtext)
font_add_google("Lobster", "lobster")

showtext_auto()

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
example2

CJK fonts

showtext includes an open source CJK (Chinese, Japanese, and Korean) font WenQuanYi Micro Hei. If you just want to show CJK text in your graph, simply specify the wqy-microhei family name in plotting functions.

Another option is to install the Source Han Sans/Serif fonts locally using the following code:

library(showtext)
font_install(source_han_serif())
font_families()
## [1] "sans"                "serif"               "mono"                "wqy-microhei"       
## [5] "source-han-serif-cn"

See ?font_install and ?source_han for more details.

source han

The internals of showtext

Every graphics device in R implements some functions to draw specific graphical elements, e.g., path() and polygon() to draw polygons, raster() to display bitmap images, text() or textUTF8() to show text, etc. What showtext does is to override their own text rendering functions and replace them by hooks provided in showtext that will further call the device's path() or raster() functions to draw the character glyphs.

This action is done only when you call showtext_begin() and won't modify the graphics device if you call showtext_end() to restore the original device functions back.

Compatibility with RStudio

Starting from version 0.9, showtext can work well with the RStudio graphics device (RStudioGD). Simply call showtext_auto() in the RStudio session and then the plots will be displayed correctly.

showtext's People

Contributors

cpsievert avatar yixuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

showtext's Issues

showtext and treemap

Hi!
I got a problem with chinese character in treemap function. Here is the code:
library(treemap)
data(GNI2014)
levels(GNI2014$continent) <- c("非洲","南极洲","亚洲","欧洲","北美洲","大洋洲","公海","南美洲")
library(showtext)
showtext.auto(enable = TRUE)
font.add('SimSun', 'simsun.ttc')
pdf(file="testtree.pdf", width = 8,height = 8)

treemap(GNI2014,
index=c("continent", "iso3"),
vSize="population",
vColor="GNI",
type="value")

dev.off()

Here is the question: The testtree.pdf can't show the chinese character!

Error loading of showtext

Hey,I am sorry to trouble you. An error appeared when I loaded it so that I did not know how to solve it.
I supposed that I need to install the freetype. Hope that you can help me,thank you very much!
Snipaste_2021-03-29_23-27-04

Is there a way to use OpenType Contextual Alternates?

Hi

Is there a way to use OpenType Contextual Alternates, using a .otf font? I am trying to use .otf fonts that do have alternates but they don't seem to be active on the ggplot charts.

Thanks for the awesome library (could not find anything as easy to use Google Fonts).

Support for Cairo::CairoPNG on Windows

I see the following on Windows:

library(showtext)
font_add_google("Lobster", "lobster")

showtext_auto()

Cairo::CairoPNG("test.png")
plot(1, pch = 16, cex = 3)
#> Error in .Call("showtext_cairo_device_bitmap", PACKAGE = "showtext") : 
#>  "showtext_cairo_device_bitmap" not available for .Call() for package "showtext"
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
dev.off()
file.show("test.png")

image

> devtools::session_info()
- Session info ------------------------------------------------------
 setting  value                       
 version  R version 3.6.2 (2019-12-12)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/Chicago             
 date     2020-05-21                  

- Packages ----------------------------------------------------------
 package     * version date       lib source                          
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.2)                  
 backports     1.1.7   2020-05-13 [1] CRAN (R 3.6.3)                  
 Cairo         1.5-12  2020-04-11 [1] CRAN (R 3.6.3)                  
 callr         3.4.3   2020-03-28 [1] CRAN (R 3.6.3)                  
 cli           2.0.2   2020-02-28 [1] CRAN (R 3.6.3)                  
 crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.2)                  
 curl          4.3     2019-12-02 [1] CRAN (R 3.6.2)                  
 desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.2)                  
 devtools      2.3.0   2020-04-10 [1] CRAN (R 3.6.3)                  
 digest        0.6.25  2020-02-23 [1] CRAN (R 3.6.3)                  
 ellipsis      0.3.1   2020-05-15 [1] CRAN (R 3.6.2)                  
 fansi         0.4.1   2020-01-08 [1] CRAN (R 3.6.2)                  
 fs            1.4.1   2020-04-04 [1] CRAN (R 3.6.3)                  
 glue          1.4.1   2020-05-13 [1] CRAN (R 3.6.2)                  
 jsonlite      1.6.1   2020-02-02 [1] CRAN (R 3.6.2)                  
 magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.2)                  
 memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.2)                  
 packrat       0.5.0   2018-11-14 [1] CRAN (R 3.6.3)                  
 pkgbuild      1.0.8   2020-05-07 [1] CRAN (R 3.6.3)                  
 pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.2)                  
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 3.6.2)                  
 processx      3.4.2   2020-02-09 [1] CRAN (R 3.6.2)                  
 ps            1.3.3   2020-05-08 [1] CRAN (R 3.6.3)                  
 R6            2.4.1   2019-11-12 [1] CRAN (R 3.6.2)                  
 remotes       2.1.1   2020-02-15 [1] CRAN (R 3.6.2)                  
 rlang         0.4.6   2020-05-02 [1] CRAN (R 3.6.3)                  
 rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.2)                  
 rstudioapi    0.11    2020-02-07 [1] CRAN (R 3.6.2)                  
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.2)                  
 showtext    * 0.8     2020-05-21 [1] Github (yixuan/showtext@5af3fed)
 showtextdb  * 2.0     2017-09-11 [1] CRAN (R 3.6.3)                  
 sysfonts    * 0.8.1   2020-05-08 [1] CRAN (R 3.6.3)                  
 testthat      2.3.2   2020-03-02 [1] CRAN (R 3.6.3)                  
 usethis       1.6.1   2020-04-29 [1] CRAN (R 3.6.3)                  
 withr         2.2.0   2020-04-20 [1] CRAN (R 3.6.3)                  

[1] C:/Users/Carson Sievert/Documents/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.2/library

Unable to replayPlot() with showtext fonts

Using replayPlot() to replay a recordPlot() doesn't render fonts correctly, even with showtext enabled:

library(showtext)
library(ggplot2)
font_add_google("Lobster", "lobster")
showtext_auto()
png("foo.png")
dev.control(displaylist = "enable")
qplot(1:10) + theme(text = element_text(family = "lobster"))
result <- recordPlot()
dev.off()
file.show("foo.png")

png("foo2.png")
replayPlot(result)
#> Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
#>   polygon edge not found
#> In addition: Warning message:
#> In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
#>   no font could be found for family "lobster"

Perhaps we can utilize recordGraphics() to ensure showtext_begin() is called when the plot has been replayed...

Fira Sans returns freetype: error code 139

Not sure if this is user error or a bug

library(showtext)
## Loading Google fonts (http://www.google.com/fonts)
font.add.google("Fira Sans", "fira")

## Automatically use showtext to render text for future devices
showtext.auto()

png("test_fira.png", 1000, 1000, res = 200)
   par(family = "fira")   
   plot(1:10, 1:10, main = "Fira Sans test")
dev.off()

Returns 50 warnings:

50: In title(...) : freetype: error code 139

and this image:

test_fira

\n in the axis title causes problem

I've encountered the following weird problem. If there is an "\n" in the begining of the axis title, axis titles disappear altogether from the ggplot.

The code to reproduce:

library(ggplot2)
library(showtext)
showtext.auto()
png("test.png")
ggplot(data=data.frame(x=rnorm(10),y=rnorm(10)),aes(x=x,y=y))+geom_point()+labs(x="\nLong line\nCanother\n(line")
dev.off()

The result is that, the x axis title together with y axis title disappear completely. If \n is removed at the begining, then everything displays perfectly. Also if we do not use showtext the bug does not appear. This bug is fully reproducible on my remote Linux server. However I can only reproduce it on this particular machine. Everything is fine on my local Macbook Pro. Here is the sessionInfo() of that particular Linux server:

R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] showtext_0.4-4     sysfonts_0.5       ggplot2_2.1.0.9001

loaded via a namespace (and not attached):
 [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     assertthat_0.1  
 [5] lazyeval_0.2.0   plyr_1.8.4       tools_3.3.1      gtable_0.2.0    
 [9] showtextdb_1.0   tibble_1.2       Rcpp_0.12.7      grid_3.3.1      
[13] munsell_0.4.3   

and the devtools::session_info()

Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, linux-gnu           
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       <NA>                        
 date     2016-10-05                  

Packages -----------------------------------------------------------------------
 package    * version    date       source                         
 assertthat   0.1        2013-12-06 CRAN (R 3.3.0)                 
 colorspace   1.2-6      2015-03-11 CRAN (R 3.3.0)                 
 devtools     1.12.0     2016-06-24 CRAN (R 3.3.0)                 
 digest       0.6.10     2016-08-02 cran (@0.6.10)                 
 ggplot2    * 2.1.0.9001 2016-10-04 Github (hadley/ggplot2@5a18687)
 gtable       0.2.0      2016-02-26 CRAN (R 3.3.0)                 
 labeling     0.3        2014-08-23 CRAN (R 3.3.0)                 
 lazyeval     0.2.0      2016-06-12 CRAN (R 3.3.0)                 
 memoise      1.0.0      2016-01-29 CRAN (R 3.3.0)                 
 munsell      0.4.3      2016-02-13 CRAN (R 3.3.0)                 
 plyr         1.8.4      2016-06-08 CRAN (R 3.3.0)                 
 Rcpp         0.12.7     2016-09-05 cran (@0.12.7)                 
 scales       0.4.0      2016-02-26 CRAN (R 3.3.0)                 
 showtext   * 0.4-4      2015-10-30 CRAN (R 3.3.1)                 
 showtextdb   1.0        2015-03-10 CRAN (R 3.3.1)                 
 sysfonts   * 0.5        2015-04-27 CRAN (R 3.3.1)                 
 tibble       1.2        2016-08-26 cran (@1.2)                    
 withr        1.0.2      2016-06-20 CRAN (R 3.3.0) 

I was not able to reproduce this on my Mac OS X 10.11.16 running R 3.3.0 with the same versions of ggplot2 and showtext. Here is the relevant devtools::session_info():

Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.0 (2016-05-03)
 system   x86_64, darwin13.4.0        
 ui       X11                         
 language (EN)                        
 collate  C                           
 tz       Europe/Vilnius              
 date     2016-10-05                  

Packages -----------------------------------------------------------------------
 package    * version    date       source                         
 Rcpp         0.12.7     2016-09-05 cran (@0.12.7)                 
 assertthat   0.1        2013-12-06 CRAN (R 3.3.0)                 
 colorspace   1.2-6      2015-03-11 CRAN (R 3.3.0)                 
 devtools     1.12.0     2016-06-24 CRAN (R 3.3.0)                 
 digest       0.6.10     2016-08-02 cran (@0.6.10)                 
 ggplot2    * 2.1.0.9001 2016-10-05 Github (hadley/ggplot2@5a18687)
 gtable       0.2.0      2016-02-26 CRAN (R 3.3.0)                 
 labeling     0.3        2014-08-23 CRAN (R 3.3.0)                 
 lazyeval     0.2.0      2016-06-12 CRAN (R 3.3.0)                 
 memoise      1.0.0      2016-01-29 CRAN (R 3.3.0)                 
 munsell      0.4.3      2016-02-13 CRAN (R 3.3.0)                 
 plyr         1.8.4      2016-06-08 CRAN (R 3.3.0)                 
 scales       0.4.0      2016-02-26 CRAN (R 3.3.0)                 
 showtext   * 0.4-4      2015-10-30 CRAN (R 3.3.0)                 
 showtextdb   1.0        2015-03-10 CRAN (R 3.3.0)                 
 sysfonts   * 0.5        2015-04-27 CRAN (R 3.3.0)                 
 tibble       1.2        2016-08-26 cran (@1.2)                    
 withr        1.0.2      2016-06-20 CRAN (R 3.3.0)                 

Will font_install() support loading in local font files?

Hi @yixuan thank you for this beautiful package! 🚀 🌻

I have a quick question regarding showtextdb::font_install(). Right now, it seems that it only supports installing fonts from an online URL. I wonder if, in the future, I will be able to use font_install() to install fonts from a local file.

Ultimately, my goal is to include private font files in a package. Here's a related SO post, but I much prefer showtext. I'm hoping I could include all the font install/registration/import in the .onload() function (e.g., with sysfonts::font_add()).

Thanks so much for your help! 🌵

showtext appears to be double spacing labels/titles

Love the ease of this package. But when I use the "\n" function to separate labels to a second line I am getting double spacing which I can't correct outside of photoshop. Here's an example with labels and titles showing the double spacing.

fpol %>% filter(pid7!="NA") %>% ggplot(., aes(x=q18_1, y=factor(pid7), fill=..x..)) +
geom_density_ridges_gradient(rel_min_height=.02) +
scale_fill_gradient2(low="dodgerblue3", high="firebrick3", mid="white", midpoint=50) +
theme_minimal() +
labs(x="", y="", title="Only Strong Republicans Are Happy\nwith Trump Admin's Management", caption="Source: February 2018") +
theme(legend.position = "none") +
scale_x_continuous(breaks=c(0,25,50,75,100), labels=c("Extremely\nUnhappy","25","Neither\nHappy\nNor\nUnhappy", "75", "Extremely\nHappy")) +
theme(text=element_text(family="JSans", size=20))

happy_w_trump

Incompatibility with ggplotGrob()

I'd like to use non-standard fonts in a ggplot but I also want to manipulate some widths so that several plots align vertically. Unfortunately after converting to a plot Grob all font information is lost. This may be related to issue #1.

R 3.5.1, ggplot2 3.0.0, showtext 0.5-1

library(ggplot2)
data <- data.frame(x = c(rnorm(1000)))

before <- ggplot(data = data) +
geom_histogram(aes(x), fill = "steelblue", color = "white", bins = 30) +
labs(title = "Histogram of Normal Random Numbers",
subtitle = "Histogram of Normal Random Numbers",
y = "Frequency",
x = "Normal Random Variable")

ggsave("before.pdf", plot = before)

(I have a need to modify widths of plots, so I create a plot Grob. Not showing that here.)

before2 <- ggplotGrob(before)
ggsave("before2.pdf", plot = before2, width = 7, height = 7)

But I want to use non-standard fonts, so...

library(showtext)
font_add_google("Schoolbell", "bell")

after <- before +
theme(text = element_text(family = "bell")) +
annotate("text", x = 2, y = 70, label = "N = 1000", size = 10, family = "bell")

as expected, the pdf has the non-standard font

showtext_auto()
ggsave("after.pdf", plot = after, width = 7, height = 7)
showtext_auto(F)

Oh, no! All text disappears

showtext_auto()
after2 <- ggplotGrob(after)
ggsave("after2.pdf", plot = after2, width = 7, height = 7)

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :

invalid font type

In addition: There were 50 or more warnings (use warnings() to see the first 50)

showtext_auto(F)

No errors or warnings but non-standard font is replaced with a serif font

showtext_auto()
ggsave("after2.svg", plot = after2, width = 7, height = 7)

Google fonts don't show on my chart, only my system default

I am using RStudio Debian 9.3 I ran this code:

library(showtext)
font_add_google("Lobster", "lobster")

showtext_auto()

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)

And I saw this in the "Plots" section of RStudio.
rplot01

Any idea why the font displays wrong?

showtext 0.9 introduces random font rendering failures with svglite

This code should produce 10 images with lobster font, but some of them will now fail (new regression with showtext 0.9). It appears some of the C refactoring done in 4dbcf25, 4ccf29d, and 921b828 is the cause of the issue

library(showtext)
font_add_google("Lobster", "lobster")
showtext_auto()
for (i in 1:10) {
  svglite::svglite(paste0("plot", i, ".svg"))
  print(qplot(1:10) + theme(text = element_text(family = "lobster")))
  dev.off()
}
system("open plot*.svg")
> devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────
 setting  value                                 
 version  R version 4.0.2 RC (2020-06-20 r78727)
 os       macOS Mojave 10.14.6                  
 system   x86_64, darwin17.0                    
 ui       RStudio                               
 language (EN)                                  
 collate  en_US.UTF-8                           
 ctype    en_US.UTF-8                           
 tz       America/Chicago                       
 date     2020-08-26                            

─ Packages ───────────────────────────────────────────────────────────────────────────────────────
 package     * version     date       lib source                               
 assertthat    0.2.1       2019-03-21 [2] CRAN (R 4.0.0)                       
 backports     1.1.9       2020-08-24 [2] CRAN (R 4.0.2)                       
 callr         3.4.3       2020-03-28 [2] CRAN (R 4.0.0)                       
 cli           2.0.2       2020-02-28 [2] CRAN (R 4.0.0)                       
 colorout      1.2-2       2020-04-27 [2] Github (jalvesaq/colorout@726d681)   
 colorspace    1.4-1       2019-03-18 [2] CRAN (R 4.0.0)                       
 crayon        1.3.4.9000  2020-06-10 [1] Github (r-lib/crayon@dcf6d44)        
 curl          4.3         2019-12-02 [1] CRAN (R 4.0.1)                       
 desc          1.2.0       2018-05-01 [2] CRAN (R 4.0.0)                       
 devtools    * 2.3.1       2020-07-21 [2] CRAN (R 4.0.2)                       
 digest        0.6.25      2020-02-23 [2] CRAN (R 4.0.0)                       
 dplyr         1.0.2       2020-08-18 [1] CRAN (R 4.0.2)                       
 ellipsis      0.3.1       2020-05-15 [2] CRAN (R 4.0.0)                       
 fansi         0.4.1       2020-01-08 [2] CRAN (R 4.0.0)                       
 farver        2.0.3       2020-01-16 [2] CRAN (R 4.0.0)                       
 fortunes      1.5-4       2016-12-29 [2] CRAN (R 4.0.0)                       
 fs            1.5.0       2020-07-31 [2] CRAN (R 4.0.2)                       
 gdtools     * 0.2.2       2020-04-03 [2] CRAN (R 4.0.0)                       
 generics      0.0.2       2018-11-29 [2] CRAN (R 4.0.0)                       
 ggplot2     * 3.3.2       2020-06-19 [1] CRAN (R 4.0.2)                       
 glue          1.4.1       2020-05-13 [2] CRAN (R 4.0.0)                       
 gtable        0.3.0       2019-03-25 [2] CRAN (R 4.0.0)                       
 htmltools     0.5.0.9000  2020-08-21 [1] Github (rstudio/htmltools@e35c3fa)   
 htmlwidgets   1.5.1.9001  2020-05-28 [1] Github (ramnathv/htmlwidgets@6fcc4b0)
 jsonlite      1.7.0       2020-06-25 [2] CRAN (R 4.0.2)                       
 labeling      0.3         2014-08-23 [2] CRAN (R 4.0.0)                       
 lifecycle     0.2.0       2020-03-06 [2] CRAN (R 4.0.0)                       
 magrittr      1.5         2014-11-22 [2] CRAN (R 4.0.0)                       
 memoise       1.1.0       2017-04-21 [2] CRAN (R 4.0.0)                       
 munsell       0.5.0       2018-06-12 [2] CRAN (R 4.0.0)                       
 pillar        1.4.6       2020-07-10 [2] CRAN (R 4.0.2)                       
 pkgbuild      1.1.0       2020-07-13 [1] CRAN (R 4.0.2)                       
 pkgconfig     2.0.3       2019-09-22 [2] CRAN (R 4.0.0)                       
 pkgload       1.1.0       2020-05-29 [2] CRAN (R 4.0.0)                       
 prettyunits   1.1.1       2020-01-24 [2] CRAN (R 4.0.0)                       
 processx      3.4.3       2020-07-05 [2] CRAN (R 4.0.2)                       
 ps            1.3.4       2020-08-11 [1] CRAN (R 4.0.2)                       
 purrr         0.3.4       2020-04-17 [2] CRAN (R 4.0.0)                       
 R6            2.4.1       2019-11-12 [2] CRAN (R 4.0.0)                       
 Rcpp          1.0.5       2020-07-06 [2] CRAN (R 4.0.2)                       
 remotes       2.2.0       2020-07-21 [2] CRAN (R 4.0.2)                       
 rlang         0.4.7       2020-07-09 [1] CRAN (R 4.0.2)                       
 rprojroot     1.3-2       2018-01-03 [2] CRAN (R 4.0.0)                       
 rstudioapi    0.11        2020-02-07 [2] CRAN (R 4.0.0)                       
 scales        1.1.1       2020-05-11 [2] CRAN (R 4.0.0)                       
 sessioninfo   1.1.1       2018-11-05 [2] CRAN (R 4.0.0)                       
 showtext    * 0.9         2020-08-13 [1] CRAN (R 4.0.2)                       
 showtextdb  * 3.0         2020-06-04 [2] CRAN (R 4.0.0)                       
 svglite       1.2.3.2     2020-07-07 [1] CRAN (R 4.0.2)                       
 sysfonts    * 0.8.1       2020-05-08 [2] CRAN (R 4.0.0)                       
 systemfonts   0.2.3       2020-06-09 [1] CRAN (R 4.0.0)                       
 testthat      2.99.0.9000 2020-08-14 [1] Github (r-lib/testthat@9e643d8)      
 tibble        3.0.3       2020-07-10 [2] CRAN (R 4.0.2)                       
 tidyselect    1.1.0       2020-05-11 [2] CRAN (R 4.0.0)                       
 usethis     * 1.6.1       2020-04-29 [2] CRAN (R 4.0.0)                       
 vctrs         0.3.2       2020-07-15 [1] CRAN (R 4.0.2)                       
 withr         2.2.0       2020-04-20 [2] CRAN (R 4.0.0)                       
 yaml          2.2.1       2020-02-01 [2] CRAN (R 4.0.0)                       

[1] /Users/cpsievert/Library/R/4.0/library
[2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Different repo for Google fonts

I just tried to use this package today to install Google fonts, but I'm getting this error:

Error: lexical error: invalid char in json text.
NA
(right here) ------^

I checked the documentation for font_add_google(), but the default repo is no longer an active site. Instead of 'http://fonts.gstatic.com', one now has to go to 'http://fonts.google.com', and manually download a font or import it through their API.

does {showtext} not work with some google fonts? eg Poppins.

sorry if this is just user error, but why doesn't font.add.google work with Google font Poppins? (https://www.google.com/fonts/specimen/Poppins )

> library(showtext)
> 
> # examples from https://github.com/yixuan/showtext.  They work:
> font.add.google("Gochi Hand", "gochi")
> font.add.google("Schoolbell", "bell")
> font.add.google("Covered By Your Grace", "grace")
> font.add.google("Rock Salt", "rock")
> 
> 
> # another font.  why doesn't this work?
> font.add.google("Poppins", "Poppins")
Error in .search.db(name) : font not found

Incorrect lineheight on high-resolution non-quartz devices

In the example below, note that without showtext enabled, all three plots below produce plots with consistent lineheight, but with showtext, the last two produce a much smaller lineheight

library(showtext)
library(ggplot2)

showtext::showtext_auto()

# lineheight appears ok
tmp <- tempfile(fileext = ".png")
png(tmp, type = "quartz", res = 220, width = 600, height = 400, units = "px")
print(qplot(1:10))
dev.off()
file.show(tmp)

# lineheight is much smaller (with showtext enabled)
tmp <- tempfile(fileext = ".png")
png(tmp, type = "cairo", res = 220, width = 600, height = 400, units = "px")
print(qplot(1:10))
dev.off()
file.show(tmp)

# lineheight is much smaller (with showtext enabled)
tmp <- tempfile(fileext = ".png")
Cairo::CairoPNG(tmp, res = 220, width = 600, height = 400, units = "px")
print(qplot(1:10))
dev.off()
file.show(tmp)

Provide a grid grob

This would be useful for people using grid graphics (e.g. ggplot2) so that you don't need to mess text rendering globally.

Cannot access bold, italic fonts from .ttc files

I have not been able to use the bold or italic font faces included in .ttc files, where all faces are in the same file. There is no problem with using .ttf font files, where each face has a different file. I can also use the plain font face from the .ttc file. This problem occurs with pdf() and quartz() devices. I am on a Mac, with R 3.4.3 and showtext 0.5.1.

Below is an MWE, although I understand paths to fonts may be different on different systems. Just pick your favorite .ttc and .ttf fonts.

Any help would be greatly appreciated. Thanks for contributing showtext to the world.

library(showtext)
font_add("Palatino",
         regular="/System/Library/Fonts/Palatino.ttc",
         bold="/System/Library/Fonts/Palatino.ttc",
         italic="/System/Library/Fonts/Palatino.ttc")
font_add("Verdana",
         regular="/Library/Fonts/Microsoft/Verdana.ttf",
         bold="/Library/Fonts/Microsoft/Verdana Bold.ttf",
         italic="/Library/Fonts/Microsoft/Verdana Italic.ttf")
fam1 <- "Palatino"
fam2 <- "Verdana"
showtext_auto()

pdf()
plot(1:10,family=fam1,font=1,main=fam1)  ## for all Palatino, titles should be bold, but they are not
plot(1:10,family=fam1,font=2,main=fam1) ## axes should be bold, but they are not
plot(1:10,family=fam1,font=3,main=fam1) ## axes should be italic, but they are not
plot(1:10,family=fam2,font=1,main=fam2)  ## for all Verdana, titles are bold (correct)
plot(1:10,family=fam2,font=2,main=fam2)  ## axes are bold (correct)
plot(1:10,family=fam2,font=3,main=fam2)  ## axes are italic (correct)
dev.off()

New R (3.4) introduces errors when using showtext

In the previous R version (3.3.3), this

library(ggplot2)
library(showtext)

font.add.google("Lato")

p1 <- ggplot(diamonds, aes(depth, price)) +
  geom_point() +
  theme_minimal(base_family = "Lato")

showtext.auto()
ggsave(plot = p1, "trial.pdf")

works:

image

but in the version of R (3.4) you instead get

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  invalid font type

Showtext prevents creating cairo-png objects when labels are blank

Created a plot, wanted to create a custom x-axis, so I set xlab to " " and xaxt="n". Found that the text and axis commands no longer drew to my graph!

library("showtext")
showtext.opts(dpi = 144)
showtext.auto()

#Open cairo-png device
png(filename = "output.png", type = "cairo-png")

# plot basic x/y graph
x<-1:10
y<-1:10
plot(x, y, ylab="Y axis",xlab=" ",xaxt = "n")

# add text and axis
text(x, y, label=y, pos=3)
axis(1, at=x, labels=x)

# close the device
dev.off()

Graph without labels

So I changed the plot line of code to be null instead of a space:

plot(x, y, ylab="Y axis",xlab="",xaxt = "n")

And then the axes and text appeared

Graph with labels

Am I missing something fundamental or is this a bug?

using showtext leads to smaller font size in ggplot2

Reproducible example.

library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point() + ggtitle("standard")

image

library(ggplot2)
showtext::showtext_auto()
ggplot(mtcars, aes(x = mpg, y = disp)) + geom_point() +
  ggtitle("showtext, no font")

image

sessioninfo::session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.0 (2021-05-18)
 os       Ubuntu 18.04.5 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language nl_BE:nl                    
 collate  nl_BE.UTF-8                 
 ctype    nl_BE.UTF-8                 
 tz       Europe/Brussels             
 date     2021-07-02                  

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
 cli           2.5.0   2021-04-26 [1] CRAN (R 4.1.0)
 colorspace    2.0-1   2021-05-04 [1] CRAN (R 4.1.0)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
 DBI           1.1.1   2021-01-15 [1] CRAN (R 4.1.0)
 digest        0.6.27  2020-10-24 [1] CRAN (R 4.1.0)
 dplyr         1.0.6   2021-05-05 [1] CRAN (R 4.1.0)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
 farver        2.1.0   2021-02-28 [1] CRAN (R 4.1.0)
 fortunes      1.5-4   2016-12-29 [1] CRAN (R 4.1.0)
 generics      0.1.0   2020-10-31 [1] CRAN (R 4.1.0)
 ggplot2     * 3.3.3   2020-12-30 [1] CRAN (R 4.1.0)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.1.0)
 labeling      0.4.2   2020-10-20 [1] CRAN (R 4.1.0)
 lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.1.0)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.1.0)
 pillar        1.6.1   2021-05-16 [1] CRAN (R 4.1.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
 R6            2.5.0   2020-10-28 [1] CRAN (R 4.1.0)
 rlang         0.4.11  2021-04-30 [1] CRAN (R 4.1.0)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.1.0)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
 showtext      0.9-2   2021-01-10 [1] CRAN (R 4.1.0)
 showtextdb    3.0     2020-06-04 [1] CRAN (R 4.1.0)
 sysfonts      0.8.3   2021-01-10 [1] CRAN (R 4.1.0)
 tibble        3.1.2   2021-05-16 [1] CRAN (R 4.1.0)
 tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.1.0)
 utf8          1.2.1   2021-03-12 [1] CRAN (R 4.1.0)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.1.0)

Fonts turn to be blurry in MacOS - Xquartz when enable showtext

require(showtext)
showtext_auto(enable = F)
plot(1)

Screen Shot 2020-09-24 at 10 28 43 AM

showtext_auto(enable = T)
plot(1)

Screen Shot 2020-09-24 at 10 29 35 AM

When I setup the dpi, font size changes

showtext_auto(enable = T)
showtext_opts(dpi = 220)
plot(1)

Screen Shot 2020-09-24 at 10 35 36 AM

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] showtext_0.9   showtextdb_3.0 sysfonts_0.8.1

loaded via a namespace (and not attached):
[1] compiler_4.0.2
>

showtext renders tiny text on higher resolution png device

Thanks for the great package.

Problem is as per this example:

library(showtext)
library(ggplot2)

p <- ggplot(mtcars, aes(x = disp, y = mpg, label = gear)) + 
  geom_smooth() +
  geom_text()

png("noshowtext.png", width = 6000, height = 4000, res = 600)
  print(p)
dev.off()

png("showtext.png", width = 6000, height = 4000, res = 600)
  showtext.begin()
  print(p)
  showtext.end()
dev.off()

Here's the version without showtext:
noshowtext

And here's the version that has it:
showtext

The text is all there, just very very small. It looks like the other objects (lines etc) are ok, but the text doesn't know how to deal with the higher resolution png device.

This has been driving me batty until I worked out that showtext is the problem. On my home setup I can get around this (now that I know what it is) by creating SVGs and using ImageMagick to convert them to PNG when I need a PNG, but I can't do that at my locked down work network. If there's a fix it would be awesome!

showtext, ggplot2 and shinyapps

Thanks for you showtext package. Recently, i want to use the WenQuanYi Micro Hei to show Chinese characters in my figures. After loading the font using the codes font.add("wqy", regular = "wqy-microhei.ttc") , the Chinese characters will show well in the figures created by the basic figure system but not for that created by the ggpplot2 package( set using the codes: theme_bw(base_family="wqy")) after publishing to the shinyapps.
How could i solve the problem? Thanks

about the fond install error

Hi,
I want to change the font in the R, the showtext package you developed behaved well, but I can not run regularly when add the font. The error can be seen below.
I have try mac OS and windows, but both of them failed.
So my questions is how to run regularly in mac or windows, can you show the one-to-one step.
Thanks a lot.

image

image

Enabling showtext in RStudio 1.4 leads to text clipping

In RStudio 1.4, I see:

library(ggplot2)
showtext::showtext_auto()
ggplot(mtcars, aes(wt, mpg)) +
  geom_point(aes(color = factor(cyl))) +
  scale_color_discrete(name = "Some very loooong name")

Screen Shot 2020-04-17 at 1 43 22 PM

Without showtext, it renders as expected

Screen Shot 2020-04-17 at 1 43 02 PM

sysfonts not loading/Image not found

After upgrading to a newer Mac, I have this error show up whenever I try to load showtext:

Error: package or namespace load failed for ‘sysfonts’: .onLoad failed in loadNamespace() for 'sysfonts', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/sysfonts/libs/sysfonts.so': dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/sysfonts/libs/sysfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/sysfonts/libs/sysfonts.so Reason: image not found

How can I fix this?

jupyter notebook

Hi Yixuan,

I wonder if you might have an idea why showtext is not working as expected in the Jupyter notebook. Is there any way I can try to debug this?

Here's a notebook showing that showtext is actually working, but not when it is displayed automatically by Jupyter...

In other words, I have to save the figure to a file and then show the file with:

library(imager)
im <- load.image("showtext-ex2.png")
plot(im, axes = FALSE)

https://gist.github.com/slowkow/771238703396bd006f3aeb0943147c85

Is it possible to modify showtext to display by default in a Jupyter notebook?

Do you know any workarounds?

R version 3.4.0 (2017-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux Server release 6.5 (Santiago)

Matrix products: default
BLAS: /apps/lib-osver/R/3.4.0/lib64/R/lib/libRblas.so
LAPACK: /apps/lib-osver/R/3.4.0/lib64/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] showtext_0.5-1 showtextdb_2.0 sysfonts_0.7.2

loaded via a namespace (and not attached):
[1] getPass_0.2-2 digest_0.6.15 crayon_1.3.4
[4] IRdisplay_0.4.4 repr_0.12.0 jsonlite_1.5
[7] magrittr_1.5 evaluate_0.10.1 stringi_1.1.6
[10] curl_3.0 uuid_0.1-2 IRkernel_0.8.10.9000
[13] Cairo_1.5-9 tools_3.4.0 stringr_1.3.0
[16] compiler_3.4.0 pbdZMQ_0.3-2

showtext.opts()' is now renamed to 'showtext_opts() . Error in Power BI Pro

I’m publishing a Power BI report with R script in Power BI Pro and getting following error. I’m not using anywhere 'showtext.opts(), 'font.add() function. How can I resolve this error.

Script Runtime Error

'showtext.opts()' is now renamed to 'showtext_opts()'
The old version still works, but consider using the new function in future code
'showtext.begin()' is now renamed to 'showtext_begin()'

Problem installing showtext.-

Hello.

I had a problem installing the package. I get the following message:

gcc -I/usr/include/R/    -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz  -I/usr/include/libpng16   -D_FORTIFY_SOURCE=2    -fpic  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4  -c util.c -o util.o
util.c: En la función ‘GetPkgEnv’:
util.c:9:23: error: expected expression before ‘==’ token
     if(TYPEOF(pkgEnv) == PROMSXP) {
                       ^
util.c: En la función ‘GetVarFromPkgEnv’:
util.c:25:23: error: expected expression before ‘==’ token
     if(TYPEOF(pkgEnv) == PROMSXP) {
                       ^
/usr/lib64/R/etc/Makeconf:134: fallo en las instrucciones para el objetivo 'util.o'
make: *** [util.o] Error 1
ERROR: compilation failed for package ‘showtext’
* removing ‘/home/vate01/R/x86_64-unknown-linux-gnu-library/3.2/showtext’
Warning in install.packages :
  installation of package ‘/home/vate01/Descargas/showtext_0.4-2.tar.gz’ had non-zero exit status

Could you please give me an advice to resolve this issue?

Thanks.

Blank display on RStudio Plots panel and warning messages

I am trying to reproduce showtext example 3 in RStudio on macOS. My R code is as follows

library(showtext)
## Add fonts that are available on macOS
"SimHei.ttf" %in% font_files()
font.add("heiti", "SimHei.ttf")

library(ggplot2)
p <- ggplot(NULL, aes(x = 1, y = 1)) + ylim(0.8, 1.2) +
  theme(axis.title = element_blank(), axis.ticks = element_blank(),
        axis.text = element_blank()) +
  annotate("text", 1, 1.1, family = "heiti", size = 15,
           label = "你好,世界!")

showtext.auto()  ## automatically use showtext for new devices

print(p)  ## on-screen device

pdf("showtext-example-3.pdf", 7, 4)  ## PDF device
print(p)
dev.off()

After running print(p) or p, the RStudio Plots panel produce a blank display without any annotated text shown in following figure

image

The output on PDF device works well. But after running print(p) or p, if I try to print p again, it will give following warning messages.

Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
3: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
4: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
5: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
6: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"

My session information is as follows:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin16.7.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.2.1  showtext_0.4-6 sysfonts_0.7.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12     showtextdb_1.0   grid_3.4.1       plyr_1.8.4       gtable_0.2.0    
 [6] scales_0.5.0     rlang_0.1.2      lazyeval_0.2.0   labeling_0.3     tools_3.4.1     
[11] munsell_0.4.3    yaml_2.1.14      compiler_3.4.1   colorspace_1.3-2 tibble_1.3.4    
Warning messages:
1: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
2: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
3: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
4: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
5: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"
6: In grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  :
  no font could be found for family "heiti"

You see when I run sessionInfo() command, it still gives the above warning messages.

Installing showtext error while compiling freetype on ubuntu 16.04

Hi,

I am using linux machine on Ubuntu 16.04
I am creating a docker image but encountered the following error installing showtext

I have installed libpng and libfreetype
apt-get install -y libpng12-dev
apt-get install -y libfreetype6-dev

Error when compiling freetype

x86_64-conda_cos6-linux-gnu-cc -I"/opt/miniconda/lib/R/include" -DNDEBUG -I/usr/include/freetype2 -I/usr/include/libpng12   -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda/include -Wl,-rpath-link,/opt/miniconda/lib  -fpic  -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda=/usr/local/src/conda-prefix  -c font_name.c -o font_name.o
In file included from /usr/include/freetype2/ft2build.h:37:0,
                 from sysfonts.h:8,
                 from font_name.c:1:
/usr/include/freetype2/freetype/config/ftheader.h:3:12: fatal error: x86_64-linux-gnu/freetype2/freetype/config/ftheader.h: No such file or directory
 #  include <x86_64-linux-gnu/freetype2/freetype/config/ftheader.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Full error logs here

Step 16/18 : RUN apt-get install -y libpng12-dev
 ---> Running in f361630f1bfc
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  dh-python distro-info-data file gir1.2-glib-2.0 iso-codes libdbus-glib-1-2
  libgirepository-1.0-1 libmagic1 libmpdec2 libpython3-stdlib
  libpython3.5-minimal libpython3.5-stdlib lsb-release mime-support
  powermgmt-base python-apt-common python3 python3-apt python3-dbus python3-gi
  python3-minimal python3-pycurl python3-software-properties python3.5
  python3.5-minimal unattended-upgrades
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libpng12-0
The following NEW packages will be installed:
  libpng12-0 libpng12-dev
0 upgraded, 2 newly installed, 0 to remove and 75 not upgraded.
Need to get 300 kB of archives.
After this operation, 905 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpng12-0 amd64 1.2.54-1ubuntu1.1 [116 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpng12-dev amd64 1.2.54-1ubuntu1.1 [183 kB]
Fetched 300 kB in 0s (516 kB/s)
Selecting previously unselected package libpng12-0:amd64.
(Reading database ... 19848 files and directories currently installed.)
Preparing to unpack .../libpng12-0_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
Selecting previously unselected package libpng12-dev:amd64.
Preparing to unpack .../libpng12-dev_1.2.54-1ubuntu1.1_amd64.deb ...
Unpacking libpng12-dev:amd64 (1.2.54-1ubuntu1.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Setting up libpng12-0:amd64 (1.2.54-1ubuntu1.1) ...
Setting up libpng12-dev:amd64 (1.2.54-1ubuntu1.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Removing intermediate container f361630f1bfc
 ---> ae270ad1974b
Step 17/18 : RUN apt-get install -y libfreetype6-dev
 ---> Running in 06d14d305342
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  dh-python distro-info-data file gir1.2-glib-2.0 iso-codes libdbus-glib-1-2
  libgirepository-1.0-1 libmagic1 libmpdec2 libpython3-stdlib
  libpython3.5-minimal libpython3.5-stdlib lsb-release mime-support
  powermgmt-base python-apt-common python3 python3-apt python3-dbus python3-gi
  python3-minimal python3-pycurl python3-software-properties python3.5
  python3.5-minimal unattended-upgrades
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libfreetype6
The following NEW packages will be installed:
  libfreetype6 libfreetype6-dev
0 upgraded, 2 newly installed, 0 to remove and 75 not upgraded.
Need to get 1271 kB of archives.
After this operation, 5135 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfreetype6 amd64 2.6.1-0.1ubuntu2.4 [315 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfreetype6-dev amd64 2.6.1-0.1ubuntu2.4 [956 kB]
Fetched 1271 kB in 0s (1565 kB/s)
Selecting previously unselected package libfreetype6:amd64.
(Reading database ... 19885 files and directories currently installed.)
Preparing to unpack .../libfreetype6_2.6.1-0.1ubuntu2.4_amd64.deb ...
Unpacking libfreetype6:amd64 (2.6.1-0.1ubuntu2.4) ...
Selecting previously unselected package libfreetype6-dev:amd64.
Preparing to unpack .../libfreetype6-dev_2.6.1-0.1ubuntu2.4_amd64.deb ...
Unpacking libfreetype6-dev:amd64 (2.6.1-0.1ubuntu2.4) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Setting up libfreetype6:amd64 (2.6.1-0.1ubuntu2.4) ...
Setting up libfreetype6-dev:amd64 (2.6.1-0.1ubuntu2.4) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Removing intermediate container 06d14d305342
 ---> 5549dd03aad7
Step 18/18 : RUN R -e "install.packages('showtext', repos='http://cran.rstudio.com/')"
 ---> Running in d655c92c3486

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-conda_cos6-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages('showtext', repos='http://cran.rstudio.com/')
also installing the dependencies ‘sysfonts’, ‘showtextdb’

trying URL 'http://cran.rstudio.com/src/contrib/sysfonts_0.8.1.tar.gz'
Content type 'application/x-gzip' length 1157505 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

trying URL 'http://cran.rstudio.com/src/contrib/showtextdb_3.0.tar.gz'
Content type 'application/x-gzip' length 1989613 bytes (1.9 MB)
==================================================
downloaded 1.9 MB

trying URL 'http://cran.rstudio.com/src/contrib/showtext_0.9.tar.gz'
Content type 'application/x-gzip' length 441983 bytes (431 KB)
==================================================
downloaded 431 KB

* installing *source* package ‘sysfonts’ ...
** package ‘sysfonts’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... x86_64-conda_cos6-linux-gnu-cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-conda_cos6-linux-gnu-cc accepts -g... yes
checking for x86_64-conda_cos6-linux-gnu-cc option to accept ISO C89... none needed
checking for pkg-config... /usr/bin/pkg-config
checking whether pkg-config could find zlib... yes
checking whether pkg-config could find libpng... yes
checking whether pkg-config could find freetype2... yes
configure: creating ./config.status
config.status: creating src/Makevars
** libs
x86_64-conda_cos6-linux-gnu-cc -I"/opt/miniconda/lib/R/include" -DNDEBUG -I/usr/include/freetype2 -I/usr/include/libpng12   -DNDEBUG -D_FORTIFY_SOURCE=2 -O2  -I/opt/miniconda/include -Wl,-rpath-link,/opt/miniconda/lib  -fpic  -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -I/opt/miniconda/include -fdebug-prefix-map=/tmp/build/80754af9/r-base_1570124924484/work=/usr/local/src/conda/r-base-3.6.1 -fdebug-prefix-map=/opt/miniconda=/usr/local/src/conda-prefix  -c font_name.c -o font_name.o
In file included from /usr/include/freetype2/ft2build.h:37:0,
                 from sysfonts.h:8,
                 from font_name.c:1:
/usr/include/freetype2/freetype/config/ftheader.h:3:12: fatal error: x86_64-linux-gnu/freetype2/freetype/config/ftheader.h: No such file or directory
 #  include <x86_64-linux-gnu/freetype2/freetype/config/ftheader.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [/opt/miniconda/lib/R/etc/Makeconf:168: font_name.o] Error 1
ERROR: compilation failed for package ‘sysfonts’
* removing ‘/opt/miniconda/lib/R/library/sysfonts’
ERROR: dependency ‘sysfonts’ is not available for package ‘showtextdb’
* removing ‘/opt/miniconda/lib/R/library/showtextdb’
ERROR: dependencies ‘sysfonts’, ‘showtextdb’ are not available for package ‘showtext’
* removing ‘/opt/miniconda/lib/R/library/showtext’

The downloaded source packages are in
        ‘/tmp/Rtmp1jZHXi/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning messages:
1: In install.packages("showtext", repos = "http://cran.rstudio.com/") :
  installation of package ‘sysfonts’ had non-zero exit status
2: In install.packages("showtext", repos = "http://cran.rstudio.com/") :
  installation of package ‘showtextdb’ had non-zero exit status
3: In install.packages("showtext", repos = "http://cran.rstudio.com/") :
  installation of package ‘showtext’ had non-zero exit status

White patches when using Google Fonts Inter in *.pdf

showtext is great, use it everyday--thanks for such a useful package!

Is this--the white patch at the joint of the lowercase 't'--a bug in the way that Inter is rendered in a *.pdf?

library(tidyverse)
library(showtext)

font_add_google("Inter")
showtext_auto()

p1 <- ggplot() +
  labs(title = "This is an Inter title") +
  theme_minimal(base_family = "Inter")

ggsave("inter_plot.pdf", p1, width = 6, height = 3)

image

Support contextual alternates

I stumpled on this, when trying to display text from my Datalegreya package. The Datalegreya font uses Contextual Alternates to elegantly make axis labels on plots. If I try to do this with showtext, the result is not rendered correctly. I created an issue for reference in my own package (https://github.com/emiltb/datalegreyar/issues/1). The following simple example illustrates the problem:

library(ggplot2)
library(showtext)
#> Loading required package: sysfonts
#> Loading required package: showtextdb

font_add("Datalegreya", "Datalegreya-Gradient.otf")
showtext_auto()

ggplot() +
  annotate("text", x = 0, y = 0, label = "{2008 }d|0a|1t|2a|2l|3e|3g|3r|2e|2y|1a|0{2018 }[2    [0    ]", family = "Datalegreya", size = 12) +
  theme_void()

Created on 2018-07-09 by the reprex package (v0.2.0).

The expected result is text looking like this:

datalegreya

Garbled text when using MS Gothic font

Hello,

I am seeing an issue when I try to use MS Gothic (installed by default in Windows 10). I have the following code:

library(showtext)
font_add("yxfont", "msgothic.ttc") # Using MS Gothic creates garbled labels on the plot
# font_add("yxfont", "arial.ttf") # Uncomment this to use Arial, and it works fine.
showtext_auto()

png(filename = 'testoutput.png', type = 'cairo', family = 'yxfont')
par(family="yxfont")

plot(1:10, 1:10, main = "ABC",)
points(c(6,2), c(2,1), pch = 3, cex = 4, col = "red")

The output PNG looks like this:

testoutput

I haven't seen this problem using other fonts.

Is this a bug?

Thank you for your work on this library.

library showtext error

Hi,I installed showtext correctly but when I libraried it ,I met an error :

library('showtext')
载入需要的程辑包:sysfonts
载入需要的程辑包:showtextdb
错误: package or namespace load failed for ‘showtext’:
loadNamespace()里算'showtext'时.onLoad失败了,详细内容:
调用: sysfonts::font_add("wqy-microhei", out_file)
错误: freetype: cannot open resource, error code 1

could you help my fix it ? thank you very much .here is my install log:

install.packages("showtext")
--- 在此連線階段时请选用CRAN的鏡子 ---
还安装相依关系‘showtextdb’

试开URL’https://mirrors.nju.edu.cn/CRAN/bin/windows/contrib/3.6/showtextdb_3.0.zip'
Content type 'application/zip' length 2012286 bytes (1.9 MB)
downloaded 1.9 MB

试开URL’https://mirrors.nju.edu.cn/CRAN/bin/windows/contrib/3.6/showtext_0.9-2.zip'
Content type 'application/zip' length 357683 bytes (349 KB)
downloaded 349 KB

程序包‘showtextdb’打开成功,MD5和检查也通过
程序包‘showtext’打开成功,MD5和检查也通过

下载的二进制程序包在
C:\Users\越冬的蚂蚱\AppData\Local\Temp\Rtmp23UzAd\downloaded_packages里

Issue with using showtext in a localized shiny::renderPlot() context

I have a use case where I'd like to enable/disable showtext via showtext_auto() in a local fashion inside shiny::renderPlot(). Here's a minimal example:

library(shiny)
library(showtext)
font_add_google("Lobster", "lobster")

with_showtext <- function(expr) {
  showtext_auto()
  on.exit(showtext_auto(FALSE))
  expr
}

ui <- fluidPage(plotOutput("base"))

server <- function(input, output, session) {
  output$base <- renderPlot({
    with_showtext({
      plot(1, pch = 16, cex = 3)
      text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
    })
  })
}

shinyApp(ui, server)

This works fine for initial draw, but not when the plot is resized. That's because, on resize, renderPlot() calls replayPlot() (instead of re-evaluating the expression), and currently doesn't know to enable showtext before replaying. We could pretty easily fix the issue if we had access to a function like showtext::is_auto_enabled(), which it seems could have an implemenation like:

is_auto_enabled = function() 
{
    any(vapply(
        getHook("before.plot.new"), 
        function(x) identical(x, showtext::showtext_begin),
        logical(1)
    ))
}

Text layer removed in PDF

Hi,

Showtext seems to remove the text layer when saving a figure as pdf.
But I need the text contained in the figures to be searchable across a report containing several pdf figures, just like any other text.

It works without using showtext_auto(), though, but I need to use specific fonts provided as ttf files.

How can I prevent the text layer from being removed?
Cheers

Font not found when not installed on system or PDF device

Using an example from the README, I can't seem to get font_add_google() to work. In addition, when the device is PDF, the output fails when the family name given to font_add_google() coincides with the full font family name, regardless of whether or not the font is installed locally.

library(showtext)
#> Loading required package: sysfonts
#> Loading required package: showtextdb

Source Serif Pro is installed on my system locally

font_add_google("Source Serif Pro", "source serif")

But Lobster is not

font_add_google("Lobster", "lobster")

showtext_auto()

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "source serif", col = "steelblue", cex = 3)
#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "source serif", :
#> no font could be found for family "source serif"

This next example works for png devices but will fail for pdf.

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "Source Serif Pro", col = "steelblue", cex = 3)

plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)
#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"
#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

#> Warning in text.default(1, 1.1, "A fancy dot", family = "lobster", col =
#> "steelblue", : no font could be found for family "lobster"

Created on 2018-10-12 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2018-10-12
#> Packages -----------------------------------------------------------------
#>  package    * version date       source                            
#>  backports    1.1.2   2017-12-13 CRAN (R 3.5.0)                    
#>  base       * 3.5.1   2018-07-05 local                             
#>  compiler     3.5.1   2018-07-05 local                             
#>  curl         3.2     2018-03-28 CRAN (R 3.5.0)                    
#>  datasets   * 3.5.1   2018-07-05 local                             
#>  devtools     1.13.6  2018-06-27 cran (@1.13.6)                    
#>  digest       0.6.17  2018-09-12 cran (@0.6.17)                    
#>  evaluate     0.11    2018-07-17 CRAN (R 3.5.0)                    
#>  graphics   * 3.5.1   2018-07-05 local                             
#>  grDevices  * 3.5.1   2018-07-05 local                             
#>  htmltools    0.3.6   2017-04-28 CRAN (R 3.5.0)                    
#>  httr         1.3.1   2017-08-20 CRAN (R 3.5.0)                    
#>  jsonlite     1.5     2017-06-01 CRAN (R 3.5.0)                    
#>  knitr        1.20    2018-02-20 CRAN (R 3.5.0)                    
#>  magrittr     1.5     2014-11-22 CRAN (R 3.5.0)                    
#>  memoise      1.1.0   2017-04-21 CRAN (R 3.5.0)                    
#>  methods    * 3.5.1   2018-07-05 local                             
#>  mime         0.6     2018-10-05 cran (@0.6)                       
#>  R6           2.3.0   2018-10-04 cran (@2.3.0)                     
#>  Rcpp         0.12.19 2018-10-01 cran (@0.12.19)                   
#>  rmarkdown    1.10    2018-06-11 cran (@1.10)                      
#>  rprojroot    1.3-2   2018-01-03 CRAN (R 3.5.0)                    
#>  showtext   * 0.5-1   2018-10-11 Github (yixuan/showtext@6bc4db4)  
#>  showtextdb * 2.0     2018-10-12 Github (yixuan/showtextdb@fe105fc)
#>  stats      * 3.5.1   2018-07-05 local                             
#>  stringi      1.2.4   2018-07-20 CRAN (R 3.5.0)                    
#>  stringr      1.3.1   2018-05-10 CRAN (R 3.5.0)                    
#>  sysfonts   * 0.8     2018-10-12 Github (yixuan/sysfonts@267566a)  
#>  tools        3.5.1   2018-07-05 local                             
#>  utils      * 3.5.1   2018-07-05 local                             
#>  withr        2.1.2   2018-03-15 CRAN (R 3.5.0)                    
#>  xml2         1.2.0   2018-01-24 CRAN (R 3.5.0)                    
#>  yaml         2.2.0   2018-07-25 CRAN (R 3.5.0)

showtext_begin() now makes evaluate+knitr+rmarkdown think there is a plot to be replayed

After #40, evaluate::evaluate() now returns a recordedplot when new_device = FALSE, even if the code shouldn't generate a plot. This presents some pretty major issues in knitr/rmarkdown.

png()
dev.control(displaylist = "enable")
showtext::showtext_begin()
res <- evaluate::evaluate("1", new_device = FALSE)
res
#> [[1]]
#> $src
#> [1] "1"
#> 
#> attr(,"class")
#> [1] "source"
#> 
#> [[2]]
#> 
#> [[3]]
#> [1] "[1] 1\n"

class(res[[2]])
#> [1] "recordedplot"

showtext and RStudioGD

showtext does not work with RStudio's built-in graphics device, despite working flawlessly with windows(). It might for example look like this:

Imgur

This is a known issue, but has not yet been fixed.

`{showtext}` does not work with `{pkgdown}`

I recently decided to use {showtext} in my {ggcharts} package. I created an onLoad() function which adds my fonts and calls showtext_auto(). When loading the package the fonts appear as expected. However, when creating my package website with {pkgdown} the fonts do not get rendered. Instead I get warnings about the font not being available (similar to when using {showtext} in RStudio). Running this on GitHub actions even throws an error (see here). Any ideas why this could be the case?

font not found

when I use font_add such as font_add('fzbs',regular = 'C:/Windows/Fonts/方正小标宋_GBK_0.TTF')
to use, there are warnings like this
warnings() 警告信息: 1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : Windows字体数据库里没有这样的字体系列 2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : Windows字体数据库里没有这样的字体系列 3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : Windows字体数据库里没有这样的字体系列 4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label), ... : Windows字体数据库里没有这样的字体系列
but this font has already installed in my font library ,and the path is right.
What 's the cause to this problem?Is there any solution?

Adding fonts on a project basis. Possible?

Is it possible to add fonts on a project basis such that it becomes self-contained and reproducible?

If so, are there any guidelines on how to do it in research compendia? Standard paths for fonts and standard approaches for font_adding with project visibility?

Can't load showtext

Hello, when I try to use showtext, it occour the following error:

Error: package or namespace load failed for ‘showtext’:
loadNamespace()里算'showtext'时.onLoad失败了,详细内容:
调用(call): utils::unzip(font_file, exdir = out_dir, overwrite = FALSE)
错误(error): 'exdir' does not exist

How can I fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.