1

Let's say I have a large dataset consisting of two columns.

The first one mentions different people (marking them with their name), while the second one is just a binary variable marking if a person mentioned in the first column was met in another dataset (it doesn't matter now in which one).

So I have something like this:

Name       Found

Peter      0

John       1

Peter      1

Mark       0

Peter      0

and so on.

I'd like to make a histogram representing: 1) the overall frequency for each name; 2) but the chart representing each name would be split into two parts by colour: found vs unfound. Something like this, actually: https://www.flickr.com/photos/gommit/6748028567, but having only two colours.

What's the best way to do so?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
DenisK
  • 140
  • 1
  • 8
  • 1
    Check out `barplot()` What you are describing is a stacked bar chart, rather than a histogram. – Badger Oct 05 '15 at 15:40
  • Possible duplicate of [Stacked Bar Plot in R](http://stackoverflow.com/questions/20349929/stacked-bar-plot-in-r) – Badger Oct 05 '15 at 15:47

1 Answers1

1

Assuming your data is in a dataframe called df, you could use table and barplot to do something like:

barplot(table(df$Found, df$Name))

enter image description here

JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116