如何在pdf上绘制中文字符?

时间:2012-10-18 06:50:20

标签: r pdf unicode plot

我的问题与我之前的问题有关。

How to plot bar plot with Chinese names in input file?

我需要在pdf上绘制中文字符。

mydata = matrix( c( 2:6, c( 2,4,2,6,3 ) ), nrow= 2 )
mylabs = c( "木材", "表", "笔", "垃圾桶", "杯" )
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )

pdf( "plotname.pdf" )
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )
dev.off()

但仅在pdf上....打印而不是中文名称。

此致

2 个答案:

答案 0 :(得分:3)

试试这个:

cairo_pdf( "plotname.pdf" )
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )
dev.off()

答案 1 :(得分:1)

我遇到了与你相同的问题(我在Mac上使用R 2.14.2和法语区域设置)。
我设法通过在pdf电话中指定字体系列“GB1”(简体中文)来解决:

pdf( "plotname.pdf" , family="GB1")
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )
dev.off()
相关问题