在Ubuntu上使用R获取反锯齿图 [英] Getting anti-aliased plots with R on Ubuntu

查看:146
本文介绍了在Ubuntu上使用R获取反锯齿图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级了我的系统并重新安装了R,现在我的标准X-11图不是反锯齿 - 它们看起来锯齿状,字体看起来很糟糕。

我似乎回忆起过去这样的问题,但不记得我做了什么。



其他一些信息:


  • qplot 也会出现非反锯齿

  • code> png 设备也会产生非反锯齿输出

  • 绘制到 pdf device,但是,产生漂亮的反锯齿输出



另一件事:我一直在运行这个版本的R / Ubuntu现在,几个月左右。我不知道这个绘图问题是否立即在新的R安装中开始,或者如果我之后做了某些事情来打破它。我不记得之前没有反锯齿,但我可能没有注意或做过很多阴谋。

任何人都知道修正是什么?目前我正在运行R 3.2.1,使用Ubuntu 14.04.3 LTS进行编译。

还有其他一些东西。遵循


  • 使用ttf-ms-fonts:

    $ b



    我希望可以看到两个图中的线和圆都是反锯齿的,但只有第二个图具有反锯齿文本。



    以下是我用来制作上述图表的代码:

      set.seed(1); 
    brownian = cumsum(runif(1e3,min = -1));
    png(brownian-no-msfonts.png,height = 400);
    par(cex = 1.3);
    plot(brownian,ylim = c(-10,15),
    ylab =Position,xlab =Time,main =Brownian Motion);
    行(布朗+7);
    dev.off()

    我确认我需要ttf-ms字体和fontconfig-ttf-ms-fonts(后者我认为配置默认使用的某些字体),以便在R中获得反锯齿文本,但只需要第一个软件包即可在Firefox中获取反锯齿文本。

    然而,我一直在玩knitr包,我注意到如果我使用render编译我的文档, rmarkdown包,那么它可以在安装或不安装ttf-ms-fonts软件包的情况下生成反锯齿图。我还没弄清楚它是如何做到这一点的。我知道它运行的Pandoc能够生成带有嵌入字体的HTML,但我不确定rmarkdown包是否包含字体,或者它是否更好地了解我的系统上哪里可以找到好的。



    我在这方面花时间感觉很肤浅,但无论如何。

    I upgraded my system and reinstalled R, and now my standard X-11 plots are not anti-aliased -- they look jagged and the font looks bad.

    I seem to recall a problem like this in the past but don't remember what I did about it.

    Some other info:

    • qplot also comes out non-anti-aliased
    • plotting to a png device produces non-anti-aliased output as well
    • plotting to a pdf device, however, produces nice looking anti-aliased output

    Another thing: I've been running this version of R/Ubuntu for a while now, a couple months or so. I don't know if this plotting problem started immediately with the new R install, or if I did something after that to break it. I don't remember noticing the lack anti-aliasing before, but I may not have been paying attention or doing a lot of plotting.

    Anyone know what the fix is? Currently I am running R 3.2.1, compiled from the source, with Ubuntu 14.04.3 LTS.

    A few more things. Following the discussion here I tried installing Cairo, but it failed. Also, I've been able to get non-anti-aliased plots in R/linux without installing Cairo in the past, and I'd rather not install extra things if not necessary.

    Here are my X11.options():

    $display
    [1] ""
    
    $width
    [1] NA
    
    $height
    [1] NA
    
    $pointsize
    [1] 12
    
    $bg
    [1] "transparent"
    
    $canvas
    [1] "white"
    
    $gamma
    [1] 1
    
    $colortype
    [1] "true"
    
    $maxcubesize
    [1] 256
    
    $fonts
    [1] "-adobe-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
    [2] "-adobe-symbol-medium-r-*-*-%d-*-*-*-*-*-*-*"
    
    $family
    [1] "sans"
    
    $xpos
    [1] NA
    
    $ypos
    [1] NA
    
    $title
    [1] ""
    
    $type
    [1] "Xlib"
    
    $antialias
    [1] "default"
    

    解决方案

    I'm running R 3.4.0 and I get anti-aliased lines, "points", and plot axes by default for X11() and png() devices.

    However, there are certain "Microsoft fonts" packages which needs to be installed on my system in order to get anti-aliased text. I can't speak for Ubuntu, but on Arch Linux the package names were "ttf-ms-fonts" and "fontconfig-ttf-ms-fonts", both in AUR. A good Google search should turn up similar packages for your own system.

    Here is are some plots produced by the png() device with and without "ttf-ms-fonts" installed.

    • Without "ttf-ms-fonts":

    • With "ttf-ms-fonts":

    I hope it is possible to see that the lines and circles in both plots are anti-aliased, but only the second plot has anti-aliased text.

    Here is the code I used to produce the above plots:

    set.seed(1);
    brownian=cumsum(runif(1e3,min=-1));
    png("brownian-no-msfonts.png",height=400);
    par(cex=1.3);
    plot(brownian,ylim=c(-10,15),
        ylab="Position",xlab="Time",main="Brownian Motion");
    lines(brownian+7);
    dev.off()
    

    I've confirmed that I need both "ttf-ms-fonts" and "fontconfig-ttf-ms-fonts" (the latter I think configures certain fonts to be used by default) in order to get the anti-aliased text in R, although only the first package is needed to e.g. get anti-aliased text in Firefox.

    However, I've been playing with the "knitr" package and I noticed that if I compile my documents using "render" from the "rmarkdown" package, then it can produce anti-aliased plots with or without the "ttf-ms-fonts" package installed. I haven't figured out how it does this. I know that it runs Pandoc which produces HTML with embedded fonts, but I'm not sure if the "rmarkdown" package itself includes fonts, or if it just has a better idea of where to find good ones on my system.

    I feel superficial for spending time on this, but whatever.

    这篇关于在Ubuntu上使用R获取反锯齿图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆