Graphics Reference
In-Depth Information
# Keep 1 out of every 'by' values in vector x
every_n <- function
function (x, by = 2 ) {
x <- sort(x)
x[seq( 1 , length(x), by = by)]
}
# Keep 1 of every 4 values in x and y
keepx <- every_n(unique(isabel$x), by = 4 )
keepy <- every_n(unique(isabel$y), by = 4 )
# Keep only those rows where x value is in keepx and y value is in keepy
islicesub <- subset(islice, x %in% keepx & y %in% keepy)
Now that we've taken a subset of the data, we can plot it, with arrowheads, as shown in Fig-
ure 13-22 :
# Need to load grid for arrow() function
library(grid)
# Make the plot with the subset, and use an arrowhead 0.1 cm long
ggplot(islicesub, aes(x = x, y = y)) +
geom_segment(aes(xend = x + vx / 50 , yend = y + vy / 50 ),
arrow = arrow(length = unit( 0.1 , "cm" )), size = 0.25 )
Search WWH ::




Custom Search