2012-07-13 44 views
5

我在this数据中创建了“DISTANCE”在变量“STATE”中的比例分布的条形图。我的代码如下:R:格点在pdf中的传奇故事

library(R.utils) 
df = loadObject("bchart.bin") 
df.prop = as.data.frame(prop.table(table(df$STATE, df$DISTANCE),1)) #Creating proportions data 
    names(df.prop) = c('State','Distance','Proportion') 

library(lattice) 
pdf(file="bchart.pdf", width=10, height=10, pointsize=10) 
barchart(State ~ Proportion, groups=Distance, data=df.prop, stack=T, horizontal=T, auto.key=list(columns=5, space="top"), par.settings = list(superpose.polygon = list(col = rev(gray.colors(5))))) 
dev.off() 

pdf文件是here。为什么当'>'打印正确时,图例将'≤'打印为'...'?这只发生在pdf或eps上。如果我使用PNG,output is fine

回答

2

它应该在使用cairo PDF后端时工作,例如,

cairo_pdf(file="bchart.pdf", width=10, height=10, pointsize=10) 

虽然我还没有检查,这很可能都与PDF编码,见Including fancy glyphs in R Graphics PDF output,由保罗·马雷尔。

+0

这可能是一个编码问题。非'latin1'语言每天都会处理这个问题,而且这不是很好。 – 2012-07-13 10:18:49

+0

完美!非常感谢,谢谢。 – user702432 2012-07-13 14:32:23