stat_contour

1,224 views
Skip to first unread message

Robert Bayesian

unread,
Jul 31, 2011, 1:42:32 PM7/31/11
to ggplot2
Hi,
I looked for an option in stat_contour  that allows me to draw values of z-axis within contour lines as in ?contour {graphics} but I have not found. Is this possible?

Robert   

Ista Zahn

unread,
Jul 31, 2011, 2:16:14 PM7/31/11
to Robert Bayesian, ggplot2
Hi Robert,
While you can probably do this in ggplot2 with some effort, the
directlabels package makes it really easy:


library(directlabels)
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")
v <- ggplot(volcano3d, aes(x, y, z = z))
v2 <- v + stat_contour(aes(colour = ..level..))
direct.label(v2)
direct.label(v2,"top.points")

Note that this example is from
http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=directlabels:direct.label

Best,
Ista

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Robert Bayesian

unread,
Aug 1, 2011, 3:22:38 AM8/1/11
to ggplot2
Thank you for the solution. I see one problem with the package you mentioned. It doesn't put the number between contour lines. please see the difference:

contour(volcano) 

Moreover, it requires colour aes(colour = ..level..) though I don't want.
Using ggplot2 I wanted to get:

par(las=1, mar=c(2,2,0,0), mgp=c(2,.7,0), tck=-.01, cex=0.8)
contour(volcano, labcex = 0.8 )
abline(h=seq(0,1,0.2), v=seq(0,1,0.2), col="gray80")

Rob

2011/7/31 Ista Zahn <iz...@psych.rochester.edu>

Ista Zahn

unread,
Aug 1, 2011, 10:52:18 AM8/1/11
to Robert Bayesian, ggplot2
Hi Rob,

On Mon, Aug 1, 2011 at 3:22 AM, Robert Bayesian
<robert....@gmail.com> wrote:
> Thank you for the solution. I see one problem with the package you
> mentioned. It doesn't put the number between contour lines.

Take a look at the directlabels docs. I think you can have fairly fine
control over where the labels appear, though I wasn't able to figure
it out without devoting more time that I have.

please see the
> difference:
>
> contour(volcano)
>
> Moreover, it requires colour aes(colour = ..level..) though I don't want.

Second part is easy enough, if a bit silly. Just set the color scale
to start and end on the same value

direct.label((v2 + scale_color_gradient(low = "#000000", high = "#000000")))

Reply all
Reply to author
Forward
0 new messages