简体   繁体   中英

Change scale of histogram in R

My histogram has only one bin in it. How can I convert it in a way such that it has more bins?

I would like to convert graph 2 in the attached image to something resembling graph 1, such that I see more bins.在此处输入图片说明

EDIT :

Upon doing hist(df$FutureCost,main="Multicare Distribution of charges", xlab="Charge($)",breaks="FD",xlim=c(0,500000)) , I was able to get a better graph. Thanks to the replies. How can I convert the numbers 1e+05, 2e+05 etc to numbers like 100000, 200000 etc.在此处输入图片说明

A complete (but not reproducible/testable) solution based on the comments above, with some attempt to reproduce the ggplot style ...

opar <- options(scipen=100)
par(bg="gray")       ## set plot background color
hist(df$FutureCost,
     main="Multicare Distribution of charges",
     xlab="Charge($)",
     breaks="FD",
     xlim=c(0,500000),col="black")
grid(col="white") ## plots on top of histogram; re-plot
                  ## histogram if you like ...
par(opar) ## restore original settings 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM