Created
April 3, 2015 18:41
-
-
Save amoeba/ab1408c231ef983b8903 to your computer and use it in GitHub Desktop.
ggplot2 geom_line() example with disconnected lines for NA values
This file contains hidden or 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