Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206305

Bar-chart with dplyr/ggplot with male/female bars side by side

$
0
0

I'm trying to

Here's the example :

df <- read.table(text = 
  "sex  var value
  m a   1
  m a   1
  m a   0
  m b   0
  m b   0
  f a   1
  f a   0
  f b   0
  f b   1", 
header = TRUE, 
stringsAsFactors = FALSE
  )

What I'd like to create is a bar-chart which has the proportions for each of the var values, for each sex.

So in the above data I would have :

var a : 
        m : 0.6
        f : 0.5
var b : 
        m : 0
        f : 0.5

But expressed as a bar-chart using ggplot


Viewing all articles
Browse latest Browse all 206305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>