Reputation: 63
I want to know how can I do a break or white space in a line plot in r using only the function plot, cause I have a big project and I can't change for ggplot. For example I have data of temperature all the month but I don have data de day 4, I need a white space or break in the line the day 4.
Upvotes: 1
Views: 335
Reputation: 5499
Insert an 'NA' value for the missing data.
set.seed(3)
x <- 1:10
y <- runif(10)
mydf <- data.frame(x = x, y = y)
plot(y ~ x, type = 'l', data = mydf, main = 'All data')
mydf_missing <- mydf[-4, ]
plot(y ~ x, type = 'l', data = mydf_missing, main = 'Missing data')
mydf_na <- mydf
mydf_na[4,2] <- 'NA'
plot(y ~ x, type = 'l', data = mydf_na, main = 'Missing replaced with NA')
Upvotes: 2