我看到了有关ggplot2或其他库的这类问题,但找不到有关基本图形的问题。
用于绘图的数据没有带有NA的空白行,
但它们会自动出现在绘图中。
1)如何删除图中的空白? 2)我可以手动调整图中的间隙大小吗?
**编辑
** 我提供了一个示例代码,其中包含较少的数据,但是它可以向您显示确切的问题。
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))
请注意,从“ bot = c ~~”开始的四行内容是为了掩盖图中的空白。
在没有代码的情况下,每个数据集的一行都会出现在图中的空白处。