Reputation: 101
All the examples I see from R hist() starts with a raw list of data, and does the frequency counts in R. My data is not raw, it's already counted and binned, for instance A, 34 B, 15 C, 82 D, 22
Can R begin with data in that form and plot a histogram from it without doing the frequency counting form me? Thanks - Ed
Upvotes: 2
Views: 2677
Reputation: 345
The new HistogramTools package on CRAN includes a private function .BuildHistogram
that does exactly this. It takes a list of breakpoints and a list of counts (breakpoints must be 1 greater than counts), and returns a valid R histogram object with the midpoints, density, and other object components setup properly so you can plot the resulting object with standard R functions.
install.packages("HistogramTools")
library(HistogramTools)
myhist <- HistogramTools:::.BuildHistogram(1:6, 1:5)
plot(myhist)
Upvotes: 1
Reputation: 21502
You could do so by assigning the class histogram
to your data with your values in the appropriately named locations, and then using plot.histogram
, but since what you have is not a set of binned samples in the first place, you don't have data that is amenable to a true histogram. As Tyler commented, just do a bar plot and assign your data category names to the x-axis.
Upvotes: 2