2012-11-29 4 views
13

ggplot2에 윤곽선의 데이터 라벨을 얻는 방법을 알고 싶습니다. 감사합니다stat_contour 라인에 데이터 레이블이 있음

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() 

답변

20

directlabels 패키지를 사용하고 ggplot와 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

에서 솔루션을 따기> 당신은'방법 = "bottom.pieces을"'추가해야합니다 (또는 것 2.0.0 'top.pieces')를'direct.label' 호출에 추가합니다 – jaimedash

관련 문제