2013-10-06 5 views
0

대체 제목 : 히스토그램의 Y 축을 0-1 범위로만 조절할 수 있습니까?y 축이 큰 산점도에서 막대 그래프 y 축 1

끔찍한 질문 제목이므로 실례를 보여주십시오. 여기의 데이터는 범위가 y 축 ... 대략 0 ~ 3.5의 데이터 범위와 거의 같도록 설정됩니다.

library(ggplot2) 
x<-runif(100)*200 
y<-runif(100)*3 
xy<-data.frame(x,y) 

p <- ggplot(xy) + theme_bw() 
p + geom_point(aes(x, y)) + 
    geom_histogram(aes(x), alpha=1/10) 

내가 히스토그램 'Y-범위는'1 The first part of this answer의 최대 확장되고 싶지는 말을, 예를 보여줍니다


당신은했으나, 필요 (..density를 ..)를 사용 * binwidth보다는 ..count ../ 합 (카운트 .. ..)

# Your data: 
all <- data.frame(fill=rep(LETTERS[1:4],c(26,24,23,29)), 
        Events=c(1,1,3,1,1,6,2,1,1,2,1,1,1,1,5,1,2,2,1,1,1,1,2,1,2,1,2,3,1,3,2,5,1,1,1,2,1,1,1,1,1,1,1,1,1,4,3,3,5,3,1,2,2,3,3,9,8,1,1,2,2,1,2,39,43,194,129,186,1,2,7,4,1,12,3,2,3,8,20,5,1,4,9,51,12,7,6,7,7,9,17,18,8,7,6,10,27,11,21,89,47,1)) 

bw <- 20 # set the binwidth 
# plot 
p1<-ggplot(all,aes(x=Events, fill=fill)) + 
    geom_histogram(aes(y=(..density..)*bw), position='dodge', binwidth=bw) 
p1 
012 3,516,

하지만 거기에는 변수 'BW'존재하지 않습니다에 대한 오류와 실패, 나를 위해 작동하지 않습니다 내가, 내가 필요한 표기를 발견

bw <- 30 
p <- ggplot(xy) + theme_bw() 
p + geom_point(aes(x, y)) + 
    geom_histogram(aes(x=x, y=..density.. * bw), alpha=1/10) 

Error in eval(expr, envir, enclos) : object 'bw' not found 

답변