I am very new to R and I am using it for my probability class. I searched for this question here, but it looks that is not the same as I want to do. (If there is already an answer, please tell me).
The problem is that I want to save multiple plots of histograms in the same file. For example, if I do this in the R prompt, I get what I want:
library(PASWR)
data(Grades)
attach(Grades) # Grade has gpa and sat variables
par(mfrow=c(2,1))
hist(gpa)
hist(sat)
So I get both histograms in the same plot. but if I want to save it as a jpeg:
library(PASWR)
data(Grades)
attach(Grades) # Grades has gpa and sat variables
par(mfrow=c(2,1))
jpeg("hist_gpa_sat.jpg")
hist(gpa)
hist(sat)
dev.off()
It saves the file but just with one plot... Why? How I can fix this? Thanks.
Also, if there is some good article or tutorial about how to plot with gplot and related stuff it will be appreciated, thanks.
Swap the order of these two lines:
par(mfrow=c(2,1))
jpeg("hist_gpa_sat.jpg")
so that you have:
jpeg("hist_gpa_sat.jpg")
par(mfrow=c(2,1))
hist(gpa)
hist(sat)
dev.off()
That way you are opening the jpeg device before doing anything related to plotting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With