大数据人|大数据第一社区

 找回密码
 注册会员

扫一扫,访问微社区

查看: 1828|回复: 0
打印 上一主题 下一主题

[其它] R语言实践中文&字体

[复制链接]
  • TA的每日心情
    奋斗
    2015-7-30 23:05
  • 签到天数: 12 天

    [LV.3]偶尔看看II

    852

    主题

    972

    帖子

    4804

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    4804
    QQ
    跳转到指定楼层
    楼主
    发表于 2015-1-4 19:48:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1. CairoPDF(file = ifelse(onefile, "Rplots.pdf","Rplotd.pdf"),
    2.          width = 6, height = 6, onefile = TRUE, family = "Helvetica",
    3.          title = "R Graphics Output", fonts = NULL, version = "1.1",
    4.          paper = "special", encoding, bg, fg, pointsize, pagecentre)
    5. library(Cairo);
    6. CairoPDF();
    7. library(Cairo);
    8. CairoPDF();
    9. plot(1:10,1:10,type="n");
    10. text(2,10,"宋体",family="SimSun");
    11. text(2,8,"黑体",family="SimHei");
    12. text(2,6,"楷体",family="KaiTi_GB2312");
    13. text(2,4,"隶书",family="LiSu");
    14. text(2,2,"幼圆",family="YouYuan");
    15. text(6,10,"Arial",family="Arial");
    16. text(6,8,"Times New Roman",family="Times New Roman");
    17. text(6,6,"Courier New",family="Courier New");
    18. text(6,4,"Consolas",family="Consolas");
    19. text(6,2,"Symbol",family="Symbol");
    20. dev.off();
    21. dev.off();

    22. library(ggplot2)
    23. library(Cairo)
    24. CairoPDF(file = "mtcars_plot.pdf")
    25. p <- ggplot(data = mtcars, aes(x=wt, y=mpg))
    26. p + geom_point() +
    27.   labs(title = "32种车型的油耗效率", x = "重量 (x1000 lb)", y = "每加仑行驶公里数") +
    28.   theme(plot.title = element_text(family="Microsoft YaHei", size=20),
    29.         axis.title.y = element_text(family="simhei", size=14),
    30.         axis.title.x = element_text(family="simsun", size=14))
    31. # 此种情况下,element_text() 中的 face 参数无效
    32. # ("plain", "italic", "bold", "bold.italic") 斜体、粗体无法显示
    33. dev.off()
    34. How to use your favorite fonts in R charts
    35. install.packages("extrafont")
    36. library(extrafont)
    37. font_import()
    38. names(pdfFont()) # 已经有中文字体
    复制代码
    如"Microsoft YaHei",但依然不能成功;只能使用“GB1”能显示中文,但不能真正指定字体,且英文字体也很怪异。


    原文地址:http://blog.sina.com.cn/s/blog_6d109e060101q0x2.html

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册会员

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条


    id="mn_portal" >首页Portalid="mn_P18" onmouseover="navShow('P18')">应用id="mn_P15" onmouseover="navShow('P15')">技术id="mn_P37" onmouseover="showMenu({'ctrlid':this.id,'ctrlclass':'hover','duration':2})">前沿id="mn_P36" onmouseover="navShow('P36')">宝箱id="mn_P61" onmouseover="showMenu({'ctrlid':this.id,'ctrlclass':'hover','duration':2})">专栏id="mn_P65" >企业id="mn_Nd633" >导航 折叠导航 关注微信 关注微博 关注我们

    QQ|广告服务|关于我们|Archiver|手机版|小黑屋|大数据人 ( 鄂ICP备14012176号-2  

    GMT+8, 2024-5-17 12:41 , Processed in 0.250250 second(s), 34 queries .

    Powered by 小雄! X3.2

    © 2014-2020 bigdataer Inc.

    快速回复 返回顶部 返回列表