multiple bar plots with proportions ggplot

时间:2018-04-26 17:01:38

标签: r ggplot2

I'm trying to make a figure using ggplot and facets; facets based on a categorical variable, and in each plot horizontal barplots of proportions. Hope this makes sense :)

dummy dataset:

testdf <- read.csv(text = "ONE,TWO
                       0.01,cat1
                       0.01,cat1
                       0.06,cat1
                       0.06,cat1
                       0.011,cat1
                       0.011,cat1
                       0.011,cat1
                       0.016,cat1
                       0.016,cat1
                       0.01,cat2
                       0.06,cat2
                       0.06,cat2
                       0.06,cat2
                       0.011,cat2
                       0.011,cat2
                       0.011,cat2
                       0.012,cat2
                       0.012,cat2")

This is what I'm hoping to get

Its not working for me, this is what I came up with so far:

  ggplot(testdf, aes(x=TWO, y=ONE)) +
  geom_jitter(position=position_jitter(width=0.3, height=0.2), aes(factor(TWO)), alpha=0.9)+
  geom_bar(stat='identity',alpha = 0.5, show.legend = FALSE, aes(fill=factor(TWO))) + facet_grid(.~TWO)+
  coord_flip()

Result

1 个答案:

答案 0 :(得分:0)

我附在那里的数字没有分数,所以我不确定你用<?php $sub='$row["message_subject"]'; $body='$row["message_body"]'; echo '<a href="#" onclick="mine($sub,$body);"><div class="sl-item unread-message"><div class="sl-avatar avatar avatar-sm avatar-circle">'; ?> 想要实现的目标。要获得geom_jitter中的内容,您可以使用

what I was hoping to get figure

导致

faceted bar plot