1

I have 21 variables in 4 distinct forms (original data, averages, log and log1p transformations). I would like to plot them in one large (long) figure of 4 cols and 21 rows. I have been playing around with the arguments a lot... "width" and "height", chaged the units, changed the resolution tried png, jpeg, pdf... bunches of combinations, but I can't manage to get the figure, I get that old message:

Error in plot.new() : figure margins too large

Sometimes, deppending on the values I choose, I get a poor figure, but then I try to open it and windows give me a message that says that I don't have permission to open that file (???). I was told that R must be writing a corrupted file. I'm brand new to R and don't know what else to do. Any tips or materials I can read to get a solution? Here is my code... If the dataframe with the variables is relevant, let me know and I'll figure a way to provide (it's huge)

####  4  Histograms ####

#install.packages("png")
  library(png) 

jpeg(filename = "histograms.jpeg", width = 30, height = 60, units = "cm", pointsize = 12, bg = "white", res = 120)

   par(pty = "m", mfrow = c(21, 4), cex.lab = 1 , cex.main = 0.9);


for(i in 1:ncol(climData_num_2)){

# All clim data
hist((climData_num_2)[,i],prob=TRUE,breaks =40, col ="thistle", xlab=(colnames((climData_num_2)[i])),main = paste("Histogram of" ,   colnames((climData_num_2)[i])))
curve(dnorm(x, mean=mean(((climData_num_2)[,i]),na.rm=TRUE), sd=sd(((climData_num_2)[,i]),na.rm=TRUE)), col="blue",lwd=2, add=TRUE)
lines(density(sort((climData_num_2)[,i])), col="red",lwd=2, add=TRUE)

# Average variables  
hist((av_cdn_2)[,i],prob=TRUE,breaks =40, col ="thistle", xlab=(colnames((av_cdn_2)[i])),main = paste("Histogram of" , colnames((av_cdn_2)[i])))
curve(dnorm(x, mean=mean(((av_cdn_2)[,i]),na.rm=TRUE), sd=sd(((av_cdn_2)[,i]),na.rm=TRUE)), col="blue",lwd=2, add=TRUE)
lines(density(sort((av_cdn_2)[,i])), col="red",lwd=2, add=TRUE)

# Log transformed
hist(log(av_cdn_2)[,i],prob=TRUE,breaks =40, col ="thistle", xlab=(colnames((av_cdn_2)[i])),main = paste("Histogram of log" , colnames((av_cdn_2)[i])))
curve(dnorm(x, mean=mean((log(av_cdn_2)[,i]),na.rm=TRUE), sd=sd((log(av_cdn_2)[,i]),na.rm=TRUE)), col="blue",lwd=2, add=TRUE)
lines(density(sort(log(av_cdn_2)[,i])), col="red",lwd=2, add=TRUE)

# log1p transformed
hist(log1p(av_cdn_2)[,i],prob=TRUE,breaks =40, col ="thistle", xlab=(colnames((av_cdn_2)[i])),main = paste("Histogram of log1p" , colnames((av_cdn_2)[i])))
curve(dnorm(x, mean=mean(log1p((av_cdn_2)[,i]),na.rm=TRUE), sd=sd(log1p((av_cdn_2)[,i]),na.rm=TRUE)), col="blue",lwd=2, add=TRUE)
lines(density(sort(log1p(av_cdn_2[,i]))), col="red",lwd=2, add=TRUE)
}



dev.off()

All suggestions are apreciated Thank you in advance

Edit:

data.frames to run the code:

av_cdn_2<-data.frame(replicate(21,sample(0:1000,30,rep=TRUE)))
climData_num_2<-data.frame(replicate(21,sample(0:1000,30,rep=TRUE)))
Thai
  • 493
  • 5
  • 15
  • Can you rewrite your code so that it is reproducible? Check out this link: [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Alex Jul 24 '17 at 19:42
  • Try adding `mar=c(1,1,1,1)` to your par statement – G5W Jul 24 '17 at 20:12
  • @Alex, thank you for this link... I'm now using deput to give you a bit of the dataframes I use.. They are huge, so I'm usig ony he first 10 lines, but I believe th core runs with this – Thai Jul 24 '17 at 20:41
  • The easiest thing would be to generate just random numbers and work with that. – Alex Jul 24 '17 at 20:43
  • @Alex, you are right. I'll edit again... the example is too messy with my original data numbers. – Thai Jul 24 '17 at 20:54
  • @G5W... Thank you, but didn't work... I still get a jpeg file which doesn't open – Thai Jul 24 '17 at 20:59
  • 2
    Additionally to what G5W suggested remove the `add` argument in `lines()`. This is working for me. – Alex Jul 24 '17 at 21:04
  • This permissions problem sounds like a different issue. What operating system are you using? – G5W Jul 24 '17 at 21:05
  • Windows 10... but some figures will open, others won't... I was told that something is going wrong during R's writing process – Thai Jul 24 '17 at 21:12
  • @Alex, is the code working for you? Are you able to generate good resolution figures? – Thai Jul 24 '17 at 21:13
  • 1
    Can you open this https://www.dropbox.com/s/zt6nqfajzl04mvn/histograms.jpeg?dl=0? – Alex Jul 24 '17 at 21:16
  • @Alex... it's not fair! What is happening with mine? Well... thank you anyway for your attention – Thai Jul 24 '17 at 21:34

0 Answers0