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?
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.
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.
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.
is this what you are looking for?
df<-data.frame(x=rnorm(50))
ggplot(df,aes(x))+geom_histogram(aes(y=..count..*10))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With