Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An approach using ggplot</p> <pre><code># convert to a data frame dept_data &lt;- as.data.frame(dept.table) </code></pre> <p>Given you are attempting to plot the proportions (not the raw numbers)</p> <pre><code># add proportions library(plyr) dept_data_prop &lt;- ddply(dept_data, .(Var1), mutate, prop = Freq /sum(Freq)) library(ggplot2) ggplot(dept_data_prop, aes(x= Var1, y = prop, colour = Var2, fill = Var2)) + geom_bar() + coord_flip() + facet_wrap(~Var1, scales = 'free', ncol = 1) + opts(strip.background =theme_blank(), strip.text.x = theme_blank(), strip.text.y = theme_text(), axis.ticks = theme_blank(), axis.title.x = theme_blank(), axis.text.x = theme_blank()) + xlab('') + scale_fill_brewer('Student', type = 'div', palette = 5) + scale_colour_brewer('Student', type = 'div', palette = 5) + scale_x_discrete(expand = c(0,0)) + scale_y_continuous(expand=c(0,0)) </code></pre> <p>To find out more about the available options, look at <code>?opts</code></p> <p>The following is adapted from <a href="http://learnr.wordpress.com/2009/03/29/ggplot2_marimekko_mosaic_chart/" rel="nofollow">learning r</a></p> <p>To get the bar widths proportional to the total counts </p> <pre><code>dept_data &lt;- as.data.frame(dept.table) names(dept_data) &lt;- c('department', 'student', 'count') dept_prop &lt;- ddply(dept_data, .(department), mutate, prop_department = count / sum(count), max_department = cumsum(prop_department), min_department = max_department - prop_department, total_department = sum(count)) dept_prop &lt;- mutate(dept_prop, prop_total = total_department / sum(count)) dept_prop &lt;- ddply(dept_prop, .(student), mutate, max_total = cumsum(prop_total), min_total = max_total - prop_total) ggplot(dept_prop, aes(xmin = min_department, xmax = max_department, ymin = min_total, ymax = max_total)) + geom_rect(aes(colour = student, fill =student)) + facet_grid(department~., scales = 'free', space = 'free') + opts(strip.background =theme_blank(), strip.text.y = theme_text(hjust = 0.05), axis.ticks = theme_blank(), axis.title.x = theme_blank(), axis.text.x = theme_blank(), axis.title.y = theme_blank(), axis.text.y = theme_blank(), legend.position = 'bottom', legend.justification = 'left', panel.border = theme_blank(), panel.background = theme_blank(), panel.grid.major = theme_blank(), panel.grid.minor = theme_blank()) + xlab('') + scale_fill_brewer('Student', palette = 'Set1') + scale_colour_brewer('Student', palette = 'Set1') + scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload