make_segments {animalEKF}R Documentation

Plot path connecting points on ggplot.

Description

Convert x-y coordinates to a data.frame for geom_path plotting on ggplot.

Usage

make_segments(xy, N=nrow(xy))

Arguments

xy

Matrix or data.frame of x-y points to plot as a path. If there are any rows that are NA-valued, the resulting path will consist of disconnected segments in those locations.

N

Number of rows of xy to plot as a path. By default, the number of rows, so all of xy.

Author(s)

Samuel Ackerman

Examples


#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_string(x="X", y="Y")) + theme_bw() 
g <- g + stat_density2d(aes_string(fill="..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_string(x="X", y="Y"), colour="red", lwd=1.5) 
g


[Package animalEKF version 1.1 Index]