2013-12-09 48 views
2

我用geom_rasterggplot繪製了52×52矩陣。ggplot2不能正確保存geom_raster()圖

代碼是在這裏:

m <- NULL 
for(i in 1:nrow(df)){ 
    for(z in 1:nrow(df)){ 
    if(df[i,][4] > df[z,][4]){m<-c(m,((df[i,][[4]]/df[z,][[4]])*100)-100)} 
    if(df[i,][4] < df[z,][4]){m<-c(m,((df[z,][[4]]/df[i,][[4]])*100)-100)} 
    if(df[i,][4] == df[z,][4]){m<-c(m,0.0)}}} 


m <- matrix(m,nrow=nrow(df)) 
colnames(m) <- df$PDB 
rownames(m) <- df$PDB 


p1 <- ggplot(melt(m),aes(Var1,Var2,fill=value)) + geom_raster() + labs(x="PDB",y="PDB") 
p1 <- p1 + theme(axis.text.x = element_text(angle=90,hjust=1)) 
print(p1) 
ggsave(file="ccs_diff_ehss.pdf") 

我的問題是,當我保存文件,我得到了以下成果:

通過文件>另存爲>: enter image description here

通過ggsave : enter image description here

print(p1)輸出:

enter image description here

正如你可以看到從print(p1)了出來作爲比ggsave和手動保存更清晰了很多。我怎樣才能保存從print(p1)輸出的圖像?

這裏是我的矩陣的subsbset:

  1a29  1cll  1clm  1cm1  1exr  1g4y  1iq5  1lin  1mxe1  1mxe2 
1a29 0.000000 18.8967136 19.0727700 3.814554 20.539906 19.3075117 9.330986 1.584507 5.6924883 5.8098592 
1cll 18.896714 0.0000000 0.1480750 14.527982 1.382034 0.3455084 8.749329 17.042172 12.4930594 12.3682751 
1clm 19.072770 0.1480750 0.0000000 14.697569 1.232134 0.1971414 8.910360 17.215482 12.6596335 12.5346644 
1cm1 3.814554 14.5279819 14.6975692 0.000000 16.110797 14.9236857 5.313737 2.195263 1.8089316 1.9219898 
1exr 20.539906 1.3820336 1.2321341 16.110797 0.000000 1.0329562 10.252281 18.659734 14.0477512 13.9212424 
1g4y 19.307512 0.3455084 0.1971414 14.923686 1.032956 0.0000000 9.125067 17.446563 12.8817324 12.7565169 
1iq5 9.330986 8.7493290 8.9103596 5.313737 10.252281 9.1250671 0.000000 7.625650 3.4425319 3.3277870 
1lin 1.584507 17.0421722 17.2154824 2.195263 18.659734 17.4465627 7.625650 0.000000 4.0439053 4.1594454 
1mxe1 5.692488 12.4930594 12.6596335 1.808932 14.047751 12.8817324 3.442532 4.043905 0.0000000 0.1110494 
1mxe2 5.809859 12.3682751 12.5346644 1.921990 13.921242 12.7565169 3.327787 4.159445 0.1110494 0.0000000 

回答

0

我意識到這是一個較舊的線程,但它看起來像它每月獲得大約7個視圖。也許這將有助於這些訪問者:

圖像查看器應用程序本身有可能應用平滑算法。我在試圖解決相同問題時遇到了您的帖子,最終發現我需要關閉PDF查看器首選項中的平滑處理。現在,輸出文件看起來與R中的繪圖相同。

這是引發我的線索(包括關於在何處查找設置的一些額外指示)。 https://groups.google.com/forum/#!topic/ggplot2/8VLuo1cw6SE