View source: R/make_segments.R
make_segments | R Documentation |
Convert x-y coordinates to a data.frame
for geom_path
plotting on ggplot
.
make_segments(xy, N=nrow(xy))
xy |
Matrix or |
N |
Number of rows of |
Samuel Ackerman
#generate toy dataset
library(ggplot2)
d <- as.data.frame(cbind(X=runif(50), Y=runif(50)))
#create segments with some missing lines so will be some gaps)
dseg <- d
dseg[ sample(20),] <- NA
g <- ggplot(d, aes(x=.data$X, y=.data$Y)) + theme_bw()
g <- g + stat_density2d(aes(fill=after_stat(!!str2lang("density"))), geom="tile", contour=FALSE)
g <- g + scale_fill_gradient(low="white", high="black") + theme(legend.position="bottom")
g <- g + geom_path(data=make_segments(xy=dseg), aes(x=.data$X, y=.data$Y), colour="red", lwd=1.5)
g
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.