Connect Lines Across Missing Values in ggplot2 Line Plot in R (Example) | Avoid Gap for NA Values

Опубликовано: 02 Октябрь 2024
на канале: Statistics Globe
731
15

How to avoid a gap in ggplot2 line plots with NA values in the R programming language. More details: https://statisticsglobe.com/connect-l...
R code of this video:

data <- data.frame(x = 1:10, # Create example data frame
y = c(3, 1, NA, 5, 5, NA, NA, 4, 3, 6))

install.packages("ggplot2") # Install & load ggplot2 package
library("ggplot2")

ggplot(data, aes(x, y)) + # Draw ggplot2 plot with missings
geom_line()

data_comp <- data[!is.na(data$y), ] # Remove missing values

ggplot(data_comp, aes(x, y)) + # Draw ggplot2 plot without missings
geom_line()

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com