简体   繁体   中英

How to plot chinese characters on pdf?

My question is related to my previous question.

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

I need to plot now chinese characters on 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()

But on pdf only .... gets printed instead of Chinese names.

Regards

Try this:

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

I had the same problem as yours (I'm on a Mac with R 2.14.2 and locale settings in french).
I managed to get around by specifying the font family "GB1" (Simplified Chinese) in the pdf call:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM