Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Accepted Solutions</h1> <hr> <h2>Chase's Answer (Modified)</h2> <p>Chase's answer had a few Xs and Ys out of place, causing the top/right axes to float unexpectedly... Here's an updated version of it:</p> <pre><code>xxx &lt;- function(x, y) { p &lt;- qplot(x,y) + geom_segment(data = data.frame(x), aes(x = x, y = max(y) + .05, xend = x, yend = max(y) + .1 )) + #top-ticks geom_segment(data = data.frame(x), aes(x = min(x), y = max(y) + .1, xend = max(x), yend = max(y) + .1 )) + #top-axis geom_segment(data = data.frame(y), aes(x = max(x) + .1, y = y, xend = max(x) + .05, yend = y)) + #right-ticks geom_segment(data = data.frame(y), aes(x = max(x) + .1, y = min(y), xend = max(x) + .1, yend = max(y) )) + #right-axis scale_x_continuous(breaks = NA) + scale_y_continuous(breaks = NA) + xlab(NULL) + ylab(NULL) + geom_text(aes(label = round(mean(x), 2), x = mean(x), y = min(y) - .2), size = 4) + geom_text(aes(label = round(mean(y), 2), x = min(x) - .2, y = mean(y)), size = 4) + geom_text(aes(label = round(max(y), 2), x = max(x) + .5, y = max(y) + .0), size = 4) + #right-max geom_text(aes(label = round(min(y), 2), x = max(x) + .5, y = min(y) - .0), size = 4) + #right-min geom_text(aes(label = round(max(x), 2), x = max(x) + .0, y = max(y) + .2), size = 4) + #top-max geom_text(aes(label = round(min(x), 2), x = min(x) + .0, y = max(y) + .2), size = 4) #top-min } x &lt;- rnorm(20) y &lt;- rnorm(20) (xxx(x, y)) </code></pre> <hr> <h2>Solution Based on Hadley's Code</h2> <p>See: <a href="https://github.com/hadley/ggplot2/wiki/Creating-a-new-geom" rel="nofollow">https://github.com/hadley/ggplot2/wiki/Creating-a-new-geom</a></p> <p>Beginning with Hadley's geom-rug.r, essentially, I've changed only the location of the rugs by tweaking these two (partial) lines:</p> <p>From</p> <pre><code> y0 = unit(0, "npc"), y1 = unit(0.03, "npc"), </code></pre> <p>to</p> <pre><code> y0 = unit(1.02, "npc"), y1 = unit(1.05, "npc"), </code></pre> <p>and from</p> <pre><code> x0 = unit(0, "npc"), x1 = unit(0.03, "npc"), </code></pre> <p>to</p> <pre><code> x0 = unit(1.02, "npc"), x1 = unit(1.05, "npc"), </code></pre> <hr> <pre><code> library(ggplot2) GeomRugAlt &lt;- proto(Geom, { draw &lt;- function(., data, scales, coordinates, ...) { rugs &lt;- list() data &lt;- coordinates$transform(data, scales) if (!is.null(data$x)) { rugs$x &lt;- with(data, segmentsGrob( x0 = unit(x, "native"), x1 = unit(x, "native"), y0 = unit(1.02, "npc"), y1 = unit(1.05, "npc"), gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) )) } if (!is.null(data$y)) { rugs$y &lt;- with(data, segmentsGrob( y0 = unit(y, "native"), y1 = unit(y, "native"), x0 = unit(1.02, "npc"), x1 = unit(1.05), "npc"), gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = size * .pt) )) } gTree(children = do.call("gList", rugs)) } objname &lt;- "rug_alt" desc &lt;- "Marginal rug plots" default_stat &lt;- function(.) StatIdentity default_aes &lt;- function(.) aes(colour="black", size=0.5, linetype=1, alpha = 1) guide_geom &lt;- function(.) "path" examples &lt;- function(.) { p &lt;- ggplot(mtcars, aes(x=wt, y=mpg)) p + geom_point() p + geom_point() + geom_rug_alt() p + geom_point() + geom_rug_alt(position='jitter') } }) geom_rug_alt &lt;- GeomRugAlt$build_accessor() x &lt;- rnorm(20) y &lt;- rnorm(20) p &lt;- qplot(x,y) p p + geom_rug() + geom_rug_alt() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload