我想从具有中文字符的输入文件中绘制条形图。
木材 2 2
表 3 4
笔 4 2
垃圾桶 5 6
杯 6 3
我希望输出像Excel这样的中文名称作为y标签和图例。我怎样才能在R中实现它?
将语言环境更改为简体中文后,我得到以下图表。
sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=zh_CN.UTF-8 LC_NUMERIC=C
[3] LC_TIME=zh_CN.UTF-8 LC_COLLATE=zh_CN.UTF-8
[5] LC_MONETARY=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] XML_3.9-4
答案 0 :(得分:1)
当你试图获得这个条形图时,你有什么问题?它对我有用,至少与Chinise角色有关。尝试
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时,可能会遇到问题。在这种情况下,请尝试jpeg:
jpeg( "plotname.jpg" )
barplot( mydata, beside=T, horiz= "T", names.arg= mylabs, las= 1, col= c( "red", "blue" ) )
dev.off()