I've got a factor with many different values. If you execute summary(factor)
the output is a list of the different values and their frequency. Like so:
A B C D
3 3 1 5
I'd like to make a histogram of the frequency values, i.e. X-axis contains the different frequencies that occur, Y-axis the number of factors that have this particular frequency. What's the best way to accomplish something like that?
edit: thanks to the answer below I figured out that what I can do is get the factor of the frequencies out of the table, get that in a table and then graph that as well, which would look like (if f
is the factor):
plot(factor(table(f)))
Update in light of clarified Q
gives:
Here we just apply
hist()
directly to the result oftable(dat)
.table(dat)
provides the frequencies per level of the factor andhist()
produces the histogram of these data.Original
There are several possibilities. Your data:
Here are three, from column one, top to bottom:
"table"
, plots the data and histogram-like barsCode to produce them:
this produces:
If you just have your data in variable
factor
(bad name choice by the way) thentable(factor)
can be used rather thantable(dat)
ortable(dat$fac)
in my code examples.For completeness, package
lattice
is more flexible when it comes to producing the dot plot as we can get the orientation you want:giving:
And a
ggplot2
version:giving: