0
怎樣才能正確顯示特殊字符(「(」,一個ggplot圖形中列名稱中使用「E」,句號,逗號等)如何在ggplot中顯示變量的特殊字符?
我的CSV的列線看起來是這樣的:?
r, á/b, ő/é, w/s (0.3), w/s (0.2), bins
。
,我想,例如,要顯示的第4個變量(在ggplot傳奇),爲 「W/S(0.3)」
這裏是我的代碼:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
fileName = paste("/2.csv", sep = "") # test file available here: https://www.dropbox.com/s/f2egxbuwwbba2q9/2.csv?dl=0
mydata = read.csv(fileName,sep=",", header=TRUE)
dataM = melt(mydata,c("bins"))
ggplot(data=dataM, aes(x= bins, y=value, colour=variable, size = variable)) +
geom_line(alpha = .9) +
scale_colour_manual(breaks=c("r","á/b","ő/é","w/s (0.3)","w/s (0.2)"), values=c("green","orange","blue","pink","yellow")) +
#scale_colour_brewer(type = "qual", palette = 7) +
scale_size_manual(breaks=c("r","á/b","ő/é","w/s (0.3)","w/s (0.2)"), values=c(1,0.5,0.5,0.5,0.5)) +
theme_bw() +
theme(plot.background = element_blank(), panel.grid.minor = element_blank(), axis.line = element_blank(),
legend.key = element_blank(), legend.title = element_blank()) +
scale_y_continuous("D", expand=c(0,0)) +
scale_x_continuous("E", expand=c(0,0)) +
theme(legend.position="bottom")
將會產生這樣的:
我們可以看到傳說中錯誤地顯示特殊字符。任何快速的方式(或不那麼快捷的方式)來解決這個問題?
(我對這個圖形的其他問題,但我認爲最好是問一個新的完整的問題,我會立即去做)
這可能取決於平臺(可能MacOS在你的情況下),語言環境和/或輸出設備(Quartz)。也許可以嘗試'Cairo'包裝中的輸出設備之一,看看它是否有幫助? – 2014-10-09 20:50:48
確實是OS X,我會檢查開羅(還沒有聽說過)。謝謝! – Rodolphe 2014-10-09 20:52:25
實際上,我認爲你可能需要的只是'read.csv(file,check.names = FALSE)' – 2014-10-09 21:03:01