Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale y-axis (counts) in ggplot2 histogram

Tags:

r

ggplot2

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?

like image 649
Leo Alekseyev Avatar asked Oct 02 '10 02:10

Leo Alekseyev


People also ask

How do I change the Y axis scale in ggplot2?

Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.

How is it possible to change the number of bins in a Ggplot histogram?

To change the number of bins in the histogram using the ggplot2 package library in the R Language, we use the bins argument of the geom_histogram() function. The bins argument of the geom_histogram() function to manually set the number of bars, cells, or bins the whole histogram will be divided into.

Can you build a histogram using ggplot2?

You can also make histograms by using ggplot2 , “a plotting system for R, based on the grammar of graphics” that was created by Hadley Wickham. This post will focus on making a Histogram With ggplot2.


1 Answers

is this what you are looking for?

df<-data.frame(x=rnorm(50))
ggplot(df,aes(x))+geom_histogram(aes(y=..count..*10))
like image 138
kohske Avatar answered Oct 06 '22 12:10

kohske