r - ggplot2 未正确保存 geom_raster() 绘图

标签 r ggplot2 save

我通过 ggplot 使用 geom_raster 绘制 52 x 52 矩阵。

代码在这里:

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) 输出的图像?

这是我的矩阵的子集:

           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

最佳答案

我意识到这是一个较旧的线程,但看起来每月大约有 7 次浏览。也许这会对那些访问者有所帮助:

图像查看器应用程序本身可能正在应用平滑算法。我在尝试解决相同问题时遇到了您的帖子,最终发现我需要关闭 PDF 查看器首选项中的平滑功能。现在输出文件看起来与 R 中的绘图相同。

这是给我提示的帖子(包括一些关于在哪里找到设置的额外说明)。 https://groups.google.com/forum/#!topic/ggplot2/8VLuo1cw6SE

关于r - ggplot2 未正确保存 geom_raster() 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20474437/

相关文章:

r - R中tcltk tktext中的重写事件

r - 将大量的 tibble 转换为单个 tibble

r - ggplot2:如何微调 geom_beeswarm 中点的位置?

python - 保存大 xlsx 文件 pandas python

r - 如何绘制同时具有连续变量和分类变量的二项式 GLM 的预测

r - 通过非唯一 id 选择数据帧的子集

r - 如何修改由 scales 包生成的标签?

r - 将 textGrob 转换为 imageGrob/rasterGrob?

android - 将视频插入android画廊

php - 使用 php 编码更新 mysql 中的现有行