tags:

views:

72

answers:

1

I am plotting a simple histogram of data sampled at, say, 10%. I want counts on the y-axis, but since the data are sampled, I want them to be scaled appropriately. If I were using base graphics, I'd do something like

foo <- rnorm(50)
foo.hist <- hist(foo,plot=F)
foo.hist$counts <- foo.hist$counts * 10
plot(foo.hist)

Is there an easy way to accomplish this with ggplot2?.. There are all sorts of "canned" y-axis transformations (scale_y_log(), etc); is there something more general-purpose?

+3  A: 

is this what you are looking for?

df<-data.frame(x=rnorm(50))
ggplot(df,aes(x))+geom_histogram(aes(y=..count..*10))
kohske
Clearly I haven't read Hadley's book carefully enough :PNow, is there a way to make 10 into a variable?.. The above code won't work if I do factor <- 10; ggplot(df,aes(x))+geom_histogram(aes(y=..count..*factor))
Leo Alekseyev
try this: fac<-10; ggplot(df,aes(x))+geom_histogram(aes(fac=fac,y=..count..*fac))
kohske