2

I plotting a 52 x 52 matrix with geom_raster through ggplot.

Code is here:

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")

The issue I have is when I save the file I get the following outputs:

Through file > save as >: enter image description here

Through ggsave: enter image description here

Output from print(p1):

enter image description here

As you can see the out from print(p1) as a lot sharper than ggsave and manual saving. How can I save the images as outputted from print(p1)?

Here is a subsbset of my matrix:

           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

2 Answers 2

2

I realize this is an older thread but it looks like it gets about 7 views a month. Perhaps this will help those visitors:

There is a chance that the image viewer application itself is applying a smoothing algorithm. I came across your post while trying to resolve the same issue and eventually discovered that I needed to turn off smoothing in the PDF viewer preferences. Now the output file looks identical to the plot in R.

This is the thread that tipped me off (includes some extra directions about where to locate the settings). https://groups.google.com/forum/#!topic/ggplot2/8VLuo1cw6SE

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at the ggsave documentation -- perhaps you can increase your resolution by manually specifying the dimensions or the dpi.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.