2014-05-23 3 views
2

검색했지만 답변을 찾을 수 없습니다. geom_bin2d으로 R에서 만든 플롯의 데이터를 추가로 처리하고 싶습니다. 나는 minmean을 포함하여 가공 한 시도R에서 구간의 끝점을 추출하는 방법은 무엇입니까?

> library(ggplot2) 
> my_plot <- ggplot(diamonds, aes(x = x, y = y))+ geom_bin2d(bins=3) 
> plot_data <- ggplot_build(my_plot) 
> data <- plot_data$data[[1]] 
> data$xbin[[1]] 
[1] [0,3.58] 
Levels: [0,3.58] (3.58,7.16] (7.16,10.7] (10.7,14.3] 

만을 사용하여 이러한 플롯에서 빈 (간격)을 추출했습니다. data$xbin[[1]]과 같은 간격의 끝점에 어떻게 액세스합니까?

(업데이트 :. 나는 내장 데이터 집합을 기반으로 완벽한 테스트 케이스로 예를 설정)

+2

이 고려

library(stringr) x <- cut(seq(1:5), breaks = 2) as.numeric(unlist(str_extract_all(as.character(x[1]), "\\d+\\.*\\d*"))) 

같은 또는 예를 들어 당신의 재현 가능한 예를 제공합니다. –

+1

['? cut'의 마지막 예] (https://stat.ethz.ch/pipermail/r-help/2008-August/170445.html) – baptiste

답변

2

뭔가

my_plot <- ggplot(diamonds, aes(x = x, y = y))+ geom_bin2d(bins=3) 
plot_data <- ggplot_build(my_plot) 
data <- plot_data$data[[1]] 
x <- data$xbin[[1]] 
as.numeric(unlist(str_extract_all(as.character(x), "\\d+\\.*\\d*")))[2] 
3.58 
관련 문제