我有一个乡村村庄的数据库,村庄的名称用阿拉伯字体记录(例如"احمدآباد").我想用R的pdf设备绘制一些变量与村庄的名称,但是在绘图之后,所有的村庄名称都在图中用点(........)显示.我还尝试使用UTF-8编码导入数据库文件,但这也没有解决问题只有一个简单的区别,在这种情况下是未知字符(..†..§....†...."§. ..).±)被点替换.我还使用extrafont库将字体加载到pdf设备,然后将它们嵌入到文件中,但它也没有解决问题.请帮助我,我在帖子中搜索但我找不到答案.
当我跑头赞扬村庄的名字是未知的字符如下.我认为在绘制这个问题之前应该解决.
> head(AllData)
Row City District Village Sampl.P. Day Month Year Tur.
2 1 Baneh ?¢?„?ˆ?? ?¨?§?±?¢?ˆ?± Network 4 4 88 0.14
3 2 Baneh ?¢?„?ˆ?? ?¨?§?±?¢?ˆ?± Network 4 4 88 0.12
4 3 Baneh ?†?…?´???± ?ƒ?ˆ?®?§?† Network 21 10 88 3.36
5 1 Bijar ?ƒ?±?§?†?? ?´???® ?¨?´?§?±?? Network 25 1 88 0.27
6 2 Bijar ?ƒ?±?§?†?? ?¢?„?¾?‡?ˆ?? Network 11 2 88 0.14
7 3 Bijar ?ƒ?±?§?†?? ?‚?±?‡ ?…??…?¯ ?„?ˆ Network 3 3 88 0.74
Run Code Online (Sandbox Code Playgroud)
我的变量的平均值与村庄的名称在下图中进行了封装.我使用以下函数制作图:
MeanRef1<- function(x,y ,DATA,v1,XLAB,YLAB,v2 ,XLIM ){
group.CI(x~y ,DATA)
with(group.CI(x~y,DATA),
segplot(y~x.lower+x.upper,center=x.mean,
draw.bands = FALSE, segments.fun = panel.arrows,
ends = "both", angle = 90, length = .03,
par.settings = simpleTheme(pch = 19, col = 1,cex = 0.5),
xlab = paste(XLAB,"±","SE"),
ylab=YLAB,
xlim=XLIM,
panel = function(x, y, z, ...) {
panel.abline(h = z, col = "grey", lty = "dashed")
panel.abline(v = v1, col = "red")
panel.abline(v = v2, col = "red")
panel.segplot(x, y, z, ...)}) )
}
Run Code Online (Sandbox Code Playgroud)
以下是调用函数的代码:
pdf("CCPPVillageGnd.pdf", width=5, height=16, pointsize = 600)# Start graph---
MeanRef1(AllData[which(AllData$Sampl.P.=="Groundwater "), ]$CCPP,AllData[which(AllData$Sampl.P.=="Groundwater "), ]$Village,AllData,4,"CCPP", "Village",10,c(-10,20) )
dev.off()# END graph------
Run Code Online (Sandbox Code Playgroud)

以下是头部的dput().
> dput(head(AllData))
structure(list(Row = c(1L, 2L, 3L, 1L, 2L, 3L), City = structure(c(1L,
1L, 1L, 2L, 2L, 2L), .Label = c("Baneh", "Bijar", "Dehgolan",
"Divandareh", "Kamyaran", "Marivan", "Qorveh", "Saghez", "Sanandaj",
"Sarvabad"), class = "factor"), District = structure(c(3L, 3L,
21L, 16L, 16L, 16L), .Label = c("", "???????", "????", "???????",
"??? ??????", "??? ?????", "????????", "??????????", "???????????",
"?????", "?????", "?????", "???? ????", "???", "???? ???", "?????",
"?????", "????????", "?????", "????", "?????", "????", "?????"
), class = "factor"), Village = structure(c(38L, 38L, 323L, 243L,
30L, 270L), .Label = c("", "??????? ????", "??????? ???? ????",
"?????", "???? ??", "????????", "????? ????", "????????", "???? ????",
"???? ???? ???", "????????", "???? ????", "???? ???? ?????",
"???????", "???????", "??????", "??????", "???????", "???????",
"?????", "?????", "?????", "??????", "????", "??????? ????",
"?????? ", "?? ???", "??????", "?? ????", "??????", "??? ?????",
"??????", "???????", "?????????", "???????", "?????", "?????",
"??????", "???????", "????????", "??????", "?????", "????????",
"??? ????", "???????", "???", "????", "???? ??", "???? ??? ??????????",
"???? ????", "?????", "??????", "?????????", "????? ????", "??????",
"????", "???????", "?????", "??????", "????????", "??????", "????? ????",
"???????", "???????", "????", "??????", "????", "??????", "???????",
"??? ??????", "????", "?????", "????????", "??????", "???????",
"????", "???? ????", "???? ???? ???? ???", "???? ???? ???? ????",
"???? ???? ??????", "????? ?????", "??? ????", "????? ????",
"????", "???? ??", "??? ????", "?????????", "????????", "??????",
"??????", "????????", "???? ????", "????????", "???????? ???? ?????",
"??????????", "????? ????", "?????", "??????? ????", "?????",
"???? ????", "??????", "???? ????", "???? ????", "????", "?????",
"?????", "????? ", "????", "???", "??? ? ???", "?????", "?????",
"?????", "???????? ????", "???????", "?? ?? ????", "??? ????",
"???? ????", "???? ???", "??? ????", "??? ???? ?????", "??? ???? ?????",
"??? ????", "??? ???", "???? ????", "???? ???? ?????", "???? ???? ?????",
"???", "???????? ???", "?Sarvabad", "??????", "???????", "?????? ??? ?????",
"???? ??", "?????", "?????", "??????", "?????", "???????", "????? ?????",
"????? ???", "???? ????", "???????", "?????? ??????", "??????",
"????? ?????", "??????", "?????? ????", "????? ????", "??? ???",
"??? ???", "??? ???", "??? ???", "???", "????", "??", "??????",
"????", "?????", "???????", "????", "?????", "?? ?????", "?? ??? ???????",
"?? ?????", "??????", "??? ??? ????", "????", "??????", "??? ??",
"???? ????", "????????", "??????", "??????", "???? ????", "???? ???",
"?????", "????? ????", "???????", "?????", "??????", "???", "??????",
"????", "?????", "???", "??????", "?????", "????", "?????", "?????",
"???", "????", "???? ?????", "???????", "??????", "???? ???",
"???? ???", "?????", "?????", "??????", "????", "?????????",
"???????", "????????", "???? ????", "????? ???? ??? ?????", "?????? ????",
"????", "??? ????", "????? ????", "?????", "??????", "?????",
"???????", "??????? ????", "??????", "???", "??? ????", "??? ????",
"??? ????", "??????", "????? ????", "????? ????", "??????", "??????",
"??????", "??? ????", "??? ???", "??????", "????", "??????",
"???? ????", "????", "???? ????", "??????", "???", "??????",
"??????", "???? ?????", "???? ?????", "???? ??????", "??? ?????",
"??? ???", "??? ????", "???? ?????", "????? ????", "???? ????",
"???? ???? ???????", "???? ???", "?????", "??? ???", "???? ????",
"??????", "??? ????", "??? ???? ??? ??", "??? ???? ?????", "??? ???? ????",
"??? ????", "???? ???", "????????", "???????", "???? ????", "?????",
"??????", "????", "???????", "?????", "??????", "??? ???? ??",
"???????", "??????", "?????", "????", "???? ??? ????", "???? ??",
"???? ?????", "???? ??????", "???? ?????", "???? ?????", "???? ???? ?????? ",
"???? ??? ????", "???? ??? ?????", "?????", "?????", "???", "???? ???",
"???? ???", "??? ????", "??????? ????", "??????", "???? ????",
"?????", "?????????", "????????", "???? ???", "???? ???", "???? ???? ??",
"???? ?????", "???? ?????", "???? ???? ???? ??", "???? ???? ?????",
"???? ???", "???? ?????", "???? ?????", "???? ????", "???? ?????",
"???????? ????", "???", "??? ???? ??????", "??? ????", "??????",
"???????", "???????", "????????", "?????", "????", "???? ???? ??????",
"???? ????", "????? ????", "????", "??? ????", "?????", "???? ??? ????",
"???? ??? ????", "???????", "???", "?????", "???? ????", "?????",
"??????", "???????", "???? ????", "????????", "????", "??????",
"??????", "??????", "????????", "???? ??", "???? ????", "?? ???",
"?? ??? ????", "?? ??? ????", "????", "?????", "?????", "??????",
"???????", "???", "??? ????", "????", "????? ???", "????? ????",
"??????", "???????", "??????", "???? ??", "?????", "???? ????",
"???????", "????", "??? ???", "??", "??? ????", "??????", "??? ?????",
"??? ????", "? . ???? ??? ??????????", "? . ????", "?. ???",
"?.??????", "?????", "??????", "?????", "??????", "??????", "????? ????",
"????? ??????? ???????", "????? ???", "????? ??????", "????",
"?????", "???? ???? ?????", "???? ??? ????", "??????? ????",
"?????", "????????", "???", "???????", "???????? ?????", "????????",
"????", "????", "?????", "???????", "???", "???? ????", "???? ????",
"????", "??? ????", "??? ????", "???? ???", "????", "????", "????? ",
"????? ????", "????? ????", "???", "????????", "???", "?????",
"????", "??????", "???????????", "?? ??", "??", "?? ????", "????",
"??? ???", "??? ????", "?????? ????", "?????? ????", "????",
"????", "??????", "???? ?????", "?????", "????", "?????", "??????????",
"????????", "???????", "???", "???? ????", "???? ????", "???? ????",
"?????????", "????? ????", "?????????", "?????? ????", "?????",
"???? ??? ???? ?????", "????? ?????", "????? ?????"), class = "factor"),
Sampl.P. = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Groundwater ",
"Network", "Reservoir"), class = "factor"), Day = c(4, 4,
21, 25, 11, 3), Month = c(4, 4, 10, 1, 2, 3), Year = c(88,
88, 88, 88, 88, 88), Tur. = c(0.14, 0.12, 3.36, 0.27, 0.14,
0.74), T = c(28.1, 27.6, 19.5, 21.2, 23.3, 25.5), pH = c(6.7,
6.6, 7.56, 7.4, 7.1, 7.7), Ecmh = c(394.2, 277.4, 408.8,
876, 313.9, 1905.3), Ecms = c(39.42, 27.74, 40.88, 87.6,
31.39, 190.53), TDS = c(252.3, 174.8, 261.6, 569.4, 200.9,
1276.6), TH = c(186.8, 145.3, 305.2, 380.5, 186.3, 704.6),
Cl = c(18.8, 6.9, 13.9, 28.9, 6, 101.2), SO4 = c(10, 2, 64,
156, 10, 600), CO3 = c(0, 0, 0, 0, 0, 0), Alk = c(119.1,
138.2, 149, 314.9, 144.2, 132.1), NO3 = c(32, 7.5, 10, 10,
16.3, 60), NO2 = c(0, 0, 0, 0, 0, 0), Ca = c(68.1, 43.2,
70.4, 104.8, 35.7, 86.4), Mg = c(4, 9.1, 31.4, 28.8, 23.6,
118.7), Na = c(NA, NA, 12, NA, NA, NA), K = c(NA, NA, 0,
NA, NA, NA), Mn = c(0, 0, 0, 0, 0, 0), As = c(0, 0, 0, 0,
0, 0), CO2 = c(4, 7, 20, 14, 8, 4), LI = c(-0.815683775,
-1.031083193, -0.035458255, 0.262299098, -0.697756373, 0.092070534
), RY = c(8.33136755, 8.662166387, 7.630916509, 6.875401803,
8.495512746, 7.515858932), CCPP = c(-50.9138138, -78.58783739,
0.045250252, 26.84998173, -28.20836319, 3.488737546), LS = c(0.310504536,
0.085594517, 0.581772243, 0.648044359, 0.131196584, 5.869947015
), SL = c(0.051036087, 0.033989865, 0.295660938, 0.45829351,
0.069971995, 0.223251159), AI = c(11.00613116, 10.77306408,
11.97783121, 12.31560623, 11.20870576, 12.15448885), PSI = c(7.81933249,
8.094229466, 7.631902546, 7.105043264, 8.026274918, 7.660141106
), DFI = c(0.083049363, 0.049943642, 0.501396512, 1.031986052,
0.108162079, 0.725720681), ME = c(-4.14803e-06, -6.43682e-06,
1.76907e-08, 5.74793e-06, -7.98249e-06, 3.79148e-06), H2Co3 = c(0.000899942,
0.001355815, 0.000170536, 0.000473944, 0.000463594, 8.55779e-05
), Hco3 = c(0.002378325, 0.002760271, 0.002964313, 0.006269787,
0.002876898, 0.002614427), Co3 = c(8.28637e-07, 7.19049e-07,
6.37456e-06, 1.11734e-05, 2.22873e-06, 1.22379e-05), CT = c(0.003279095,
0.004116806, 0.003141224, 0.006754904, 0.003342721, 0.002712242
), pHs = c(7.515683775, 7.631083193, 7.595458255, 7.137700902,
7.797756373, 7.607929466), pHeq = c(7.21203506, 7.167936921,
7.559013963, 7.170358539, 7.569237828, 7.555717826)), .Names = c("Row",
"City", "District", "Village", "Sampl.P.", "Day", "Month", "Year",
"Tur.", "T", "pH", "Ecmh", "Ecms", "TDS", "TH", "Cl", "SO4",
"CO3", "Alk", "NO3", "NO2", "Ca", "Mg", "Na", "K", "Mn", "As",
"CO2", "LI", "RY", "CCPP", "LS", "SL", "AI", "PSI", "DFI", "ME",
"H2Co3", "Hco3", "Co3", "CT", "pHs", "pHeq"), row.names = c(NA,
6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
使用cairo_pdf生成下面的图,但仍然将字符分开并反转.
jpeg("CCPPVillageNet.jpg", width=5, height=10, units="in", res=600)
MeanRef1(AllData[which(AllData$Sampl.P.=="Groundwater "), ][1:100,]$CCPP,AllData[which(AllData$Sampl.P.=="Groundwater "), ][1:100,]$Village,AllData,4,"CCPP", "Village",10,c(-10,20) )
dev.off()
Run Code Online (Sandbox Code Playgroud)

sessionInfo()也如下:
> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Farsi_Iran.1256 LC_CTYPE=Farsi_Iran.1256
[3] LC_MONETARY=Farsi_Iran.1256 LC_NUMERIC=C
[5] LC_TIME=Farsi_Iran.1256
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] Cairo_1.5-6 latticeExtra_0.6-26
[3] RColorBrewer_1.1-2 Rmisc_1.5
[5] plyr_1.8.1 lattice_0.20-29
loaded via a namespace (and not attached):
[1] grid_3.1.1 Rcpp_0.11.2 tools_3.1.1
>
Run Code Online (Sandbox Code Playgroud)
该Cairo软件包可能会有所帮助。
library(Cairo)\n\nCairoPDF("test.pdf")\nplot(0, main="\xd8\xad\xd9\x85\xd8\xaf \xd8\xa2\xd8\xa8\xd8\xa7\xd8\xaf")\ndev.off()\nRun Code Online (Sandbox Code Playgroud)\n\n编辑
\n\n根据您的数据,名称可以使用cairo_pdf
# add libraries\nlibrary(latticeExtra)\nlibrary(Rmisc)\n\n# tweak your code so the subset of data plots\ncairo_pdf("CCPPVillageGnd.pdf")\nMeanRef1(AllData$CCPP, AllData$Village,\n AllData, 4, "CCPP", "Village", 10, c(-10,20) )\ndev.off()\nRun Code Online (Sandbox Code Playgroud)\n\n返回
\n\n