Skip to content

Instantly share code, notes, and snippets.

@briandk
Created February 20, 2011 15:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandk/836059 to your computer and use it in GitHub Desktop.
Save briandk/836059 to your computer and use it in GitHub Desktop.
This file demonstrates that a new ggplot2 geom I've created--which puts rug fringes on the top/right--seems to plot just fine when sourced from a single script.
geom_rug_alt <- function(mapping = NULL,
data = NULL,
stat = "identity",
position = "identity",
...
)
{
GeomRugAlt$new(mapping = mapping,
data = data,
stat = stat,
position = position,
...
)
}
GeomRugAlt <- proto(
Geom, {
objname <- "rug_alt"
draw <- function(., data, scales, coordinates, ...) {
rugs <- list()
data <- coordinates$transform(data, scales)
if (!is.null(data$x)) {
rugs$x <- with(data, segmentsGrob(
x0 = unit(x, "native"), x1 = unit(x, "native"),
y0 = unit(1 - 0.03, "npc"), y1 = unit(1, "npc"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
))
}
if (!is.null(data$y)) {
rugs$y <- with(data, segmentsGrob(
y0 = unit(y, "native"), y1 = unit(y, "native"),
x0 = unit(1, "npc"), x1 = unit(1 - 0.03, "npc"),
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt)
))
}
gTree(children = do.call("gList", rugs))
}
default_stat <- function(.) StatIdentity
default_aes <- function(.) aes(colour="black", size=0.5, linetype=1, alpha = 1)
guide_geom <- function(.) "path"
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment