[R] [FORGED] Can fallback font be specified?
Jinsong Zhao
jszhao at yeah.net
Mon Mar 27 02:55:20 CEST 2017
On 2017/3/27 6:46, Paul Murrell wrote:
> Hi
>
> The following code uses 'gridSVG' to export the plot to SVG (after using
> 'gridGraphics' to convert the plot to using 'grid'), which allows you to
> specify a "font stack" for the exported SVG. In this example, I am
> adding "SimHei" to the "serif" font stack. I attach a screen shot of
> what the result looks like for me in Firefox on Windows (because I am
> not sure what it should look like). The idea here is really just to
> pass the effort of deciding which font to use on to a web browser.
>
> library(gridSVG)
> library(gridGraphics)
>
> fonts <- getSVGFonts()
> fonts$serif <- c(fonts$serif, "SimHei")
> setSVGFonts(fonts)
>
> plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family="serif")
>
> grid.echo()
> grid.export("test-1.svg", xmldecl='')
>
> Does that help at all?
>
> Paul
Thank you very much.
The code solve my concerns about fonts. gridGraphics make me to draw my
plot in base graphics that I used to. I can convert SVG to any other
format using Inkscape.
Best,
Jinsong
>
> On 24/03/2017 3:24 a.m., Jinsong Zhao wrote:
>> Hi there,
>>
>> I am a Chinese R user. I hope to plot the following code with Chinese in
>> one font family, such as SimHei, but English in another font family,
>> such as Times New Roman.
>>
>> plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "serif")
>>
>> In my case, the system default font is "SimSun", so the above code
>> fallback "\u4F60\u597D", which is not in the font Times, to SimSun.
>>
>> If I use:
>>
>> plot(1:10, type = "n", xlab = "Hello \u4F60\u597D", family = "SimHei")
>>
>> Then The "Hello" will in "SimHei" family, it's not as beautiful as Times.
>>
>> Is it possible to specify the fallback font family in R? Any hints or
>> suggestions?
>>
>> Thanks in advance.
>>
>> Best,
>> Jinsong
>>
More information about the R-help
mailing list