2012-11-29 10 views
13

Zastanawiam się, jak uzyskać etykiety danych na liniach w ggplot2 dla konturów. Dziękistat_contour z etykietami danych na liniach

require(grDevices) # for colours 

x <- seq(-4*pi, 4*pi, len = 27) 
y <- seq(-4*pi, 4*pi, len = 27) 
r <- sqrt(outer(x^2, y^2, "+")) 

rx <- range(x <- 10*1:nrow(volcano)) 
ry <- range(y <- 10*1:ncol(volcano)) 
ry <- ry + c(-1, 1) * (diff(rx) - diff(ry))/2 

plot(
    x = 0 
    , y = 0 
    , type = "n" 
    , xlim = rx 
    , ylim = ry 
    , xlab = "" 
    , ylab = "" 
) 

contour(
    x = x 
    , y = y 
    , z = volcano 
    , add = TRUE 
) 

library(ggplot2) 
library(reshape2) 
volcano3d <- melt(volcano) 
names(volcano3d) <- c("x", "y", "z") 

# Basic plot 
v <- ggplot(volcano3d, aes(x, y, z = z)) 
v + stat_contour() 

Odpowiedz

20

użyciu pakietu directlabels i zbierając rozwiązanie z this

# Basic plot 
v <- ggplot(volcano3d, aes(x, y, z = z)) 
library(directlabels) 
v2 <- v + stat_contour(aes(colour = ..level..)) 
direct.label(v2) 

enter image description here

+6

z ggplot> 2.0.0 trzeba dodać 'method = "bottom.pieces"' (lub 'top.pieces') do wywołania' direct.label' – jaimedash

Powiązane problemy