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

Published: 20 January 2023
on channel: 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


Watch video Connect Lines Across Missing Values in ggplot2 Line Plot in R (Example) | Avoid Gap for NA Values online without registration, duration hours minute second in high quality. This video was added by user Statistics Globe 20 January 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 731 once and liked it 15 people.