public
Created

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.

  • Download Gist
geom-rug-alt-demonstration.R
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
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"
}
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.