Created
January 1, 2016 21:54
-
-
Save dmarcelinobr/6884a308619e1e6a9750 to your computer and use it in GitHub Desktop.
ggplot2 geom_line() example with disconnected lines for NA values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ggplot2 example | |
# Show how geom_line() does not connect the line through NA values | |
library(ggplot2) | |
# Make some fake data | |
mydata <- data.frame(x = 2000:2010, y = rnorm(11, 5, 2)) | |
# First plot, all lines are connected correctly | |
ggplot(mydata, aes(x, y)) + geom_line() | |
# Now let's make some of the values NA | |
mydata[sample(1:nrow(mydata), 2, replace = FALSE),"y"] <- NA | |
# Now plot the result with the new NAs introduced | |
ggplot(mydata, aes(x, y)) + geom_line() | |
# We should see a plot with disconnected lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment