I saw this kind of questions about ggplot2 or other libraries, but cannot find one about the base graphics.
The data used for the plot does not have blank rows with NAs,
but they appear in the plot automatically.
1) How can I remove the blank space in the plot? 2) Can I manually adjust the gap size in the plot?
** edit
** I provide an example code with smaller # of data, but it can show you the exact problem.
x = c(seq.POSIXt(from = as.POSIXct("2018-07-27 00:00:00", format = "%Y-%m-%d
%H:%M:%S"),
to = as.POSIXct("2018-07-27 10:00:00", format = "%Y-%m-%d
%H:%M:%S"),
by = "1 hour"),
seq.POSIXt(from = as.POSIXct("2018-09-01 00:00:00", format = "%Y-%m-%d
%H:%M:%S"),
to = as.POSIXct("2018-09-01 08:00:00", format = "%Y-%m-%d
%H:%M:%S"),
by = "1 hour"))
y1 = 20 + rnorm(20)
y2 = 10 + rnorm(20)
y3 = 5 + rnorm(20)
date0601 = as.POSIXct("2018-06-01", format = "%Y-%m-%d")
date0930 = as.POSIXct("2018-09-30", format = "%Y-%m-%d")
dates = seq.POSIXt(from = date0601, to = date0930, by = "15 days")
lab_dates = strftime(dates, format = "%m-%d")
par(mfrow = c(1, 1),
mar = c(5.1, 5.1, 2.1, 5.1))
plot(x, y1,
axes = FALSE, xaxs = "i",yaxs = "i",
xlab = "Date", ylab = "Moisture Content (%)", ylim = c(0, 35),
type = "l", lwd = 2, col = "black", cex.lab = 2.0, cex.axis = 2.0, mgp =
c(3, 0, 0))
points(x, y2, type = "l", lwd = 2, col = "red")
bot = c(x[11], x[12])
top = c(10, 28)
rect(bot[1], top[1], bot[2], top[2], border = "white",
col = "white") # rectangular to mask gap interval
axis(1, at = dates, labels = lab_dates,
cex.axis = 2.0, mgp = c(0, 1.0, 0.0))
axis(2, at = seq(0, 35, 10), labels = seq(0, 35, 10),
cex.axis = 2.0, mgp = c(10, 0.5, 0.0))
par(new = TRUE)
plot(x, y3, type = "h", lwd = 2, col = "blue", ylim = c(0, 40),
axes = FALSE, xaxs = "i", yaxs = "i", xlab = "", ylab = "")
axis(4, at = seq(0, 40, 10), labels = seq(0, 40, 10),
cex.axis = 2.0, mgp = c(10, 1.0, 0.0))
note that four lines from "bot = c~~" are for masking the gap in the plot.
Without the code, a line for each dataset will appear in the gap in the plot.