So, this is the first time using ggplot to make a histogram and what I see is that for my data the histogram exported is the one below.
What I don't like, is the fact that the first bin does not include the zero and it starts at about 5 or 6. Has anyone encountered something like this?
I have used a range of binwidths, from 1 to 20 and it keeps doing it.
Data:
structure(list(V1 = c(8, 4.4, 9.4, 29.4, 135.6, 65, 70.9, 15.2, 38.8, 87.2, 5.2, 0.2, 7.8, 46.4, 35.9, 77.4, 34.2, 157.4, 46.4, 19, 43.8, 41.2, 96.8, 25.6, 40.2, 111.8, 111.8, 49.8, 39.4, 9.6, 11.6, 8.6, 44.2, 41, 4.6, 36.2, 12.4, 45.8, 0, 30.8, 134.6, 167.2, 13.8, 56.6, 112.3, 13.6, 18.8, 18.2, 7, 40.4, 30.8, 130.2, 234.6, 106.2, 87.2, 15, 7.6, 63, 18, 2.6, 28, 24, 153.2, 24.4, 69.6, 27, 134, 181.6, 46, 85.4, 18.6, 32, 83.6, 42.6, 32.8, 127.5, 92.8, 122, 129.6, 35.4, 20.6, 88, 14.8, 12.8, 33.8, 58.6, 104.2, 0.2)), class = "data.frame", row.names = c(NA, -88L))
Code:
library(ggplot2)
library(scales)
dat = read.csv('mo.csv')
p2=ggplot(dat, aes(x = dat$v2)) +
geom_histogram(color="black", fill="grey40", bins=25)+
scale_x_continuous(breaks = seq(0, 255, 25), limits = c(0,255), expand=c(0,0))+
scale_y_continuous(expand = c(0,0),limits = c(0,16.5), breaks = pretty(dat$v2, n = 140))
p2
ggplot(dat, aes(x = dat$V1)) +
geom_histogram(color="black", fill="grey40", bins=20)+
scale_x_continuous(breaks = seq(0,250,25))+
scale_y_continuous(expand = c(0,0),limits = c(0,16.5), breaks = pretty(dat$V1, n = 140))
This seems to be what you're looking for. Although 25 bins looks way better than 20, imo.
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