I am running code which I ran successfully on my work laptop. But on my home laptop when I get to the second 'plot' command it seems to start a new plot and overwrites what was there before. ????
What has changed and how can I prevent this?
cases<-read.csv("exporttablenewhist.csv")
str(cases)
date<-cases[,1]
modhistcase<-cases[,2]
realhistcase<-cases[,3]
lockdownhist<-cases[,4]
modhistdeaths<-cases[,5]
realhistdeaths<-cases[,6]
datereal<-as.Date(date,"%d/%m/%Y")
# Create new output window
dev.new(width=12, height=7.5)
# We suggest a 6" by 3.75" window to facilitate importing into word document (default values ~golden ratio)
#
# Adjust the margin of plot (bottom,left,top,right)
par(mar=c(5, 5, 3, 7))
#
plot(datereal, realhistcase, type = "l", lwd=2, col = "green", xaxt = "n", xlab="Month",ylab="Daily new cases")
which(substr(datereal, 9, 10) == "01")
labs <- datereal[substr(datereal, 9, 10) == "01"]
ids <- seq_along(labs)[(seq_along(labs) + 0) %% 2 == 0]
axis.Date(1, at=labs[ids], format="%b %y", cex.axis=.9)
lines(datereal,modhistcase, lwd=2,col = "blue")
legend(datereal[1],50000, legend=c("reported cases",
"modelled known cases",
"lockdown %"),
col=c("green","blue","red"),lty=1)
plot(lockdownhist,type="l",lwd=2,lty=1,col = "red",xaxt = "n", yaxt = "n", xlab= "", ylab `
="",ylim=c(0,100))
axis(side=4)
mtext("lockdown percentage", side=4, line=3)
axis(4,seq(0,100,by=10))
IMAGES BEFORE AND AFTER SECOND PLOT COMMAND
question from:
https://stackoverflow.com/questions/65650876/why-is-my-plot-on-the-right-hand-axis-overwriting-my-existing-plot