0

This is the head of a data set containing 101302 observations. It is listing vehicle weight, and the number of registrations. I want to plot this as a histogram in R.

r   mkg
3   1495
1   1447
1   1401
1   2405
1   2635
2   2515

I need to plot a histogram of the mkg variable, but I need to allow for the number of registrations. I'm not sure how to approach this. I'm sorry, I'm sure this is basic but I've looked all day for an answer and haven't found one that works.

steveb
  • 5,382
  • 2
  • 27
  • 36
Susan
  • 101
  • 8
  • Thank you! I didn't have the language to even search for the question. This is, indeed, a duplicate. – Susan Mar 28 '16 at 02:41

1 Answers1

0

Using ggplot2 package, you can try something like this:

library(ggplot2)
ggplot(df, aes(x = mkg)) + geom_histogram() + facet_wrap(~r)

It will make as many plots as there are unique values in column r.

If you want to plot all histograms on the same plot, you can try this:

library(ggplot2)
ggplot(df, aes(x = mkg, fill = r)) + geom_histogram()
Gopala
  • 10,363
  • 7
  • 45
  • 77