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