Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First you need to get the counts for each category, i.e. how many Bads and Goods and so on are there for each group (Food, Music, People). This would be done like so:</p> <pre><code>raw &lt;- read.csv("http://pastebin.com/raw.php?i=L8cEKcxS",sep=",") raw[,2]&lt;-factor(raw[,2],levels=c("Very Bad","Bad","Good","Very Good"),ordered=FALSE) raw[,3]&lt;-factor(raw[,3],levels=c("Very Bad","Bad","Good","Very Good"),ordered=FALSE) raw[,4]&lt;-factor(raw[,4],levels=c("Very Bad","Bad","Good","Very Good"),ordered=FALSE) raw=raw[,c(2,3,4)] # getting rid of the "people" variable as I see no use for it freq=table(col(raw), as.matrix(raw)) # get the counts of each factor level </code></pre> <p>Then you need to create a data frame out of it, melt it and plot it:</p> <pre><code>Names=c("Food","Music","People") # create list of names data=data.frame(cbind(freq),Names) # combine them into a data frame data=data[,c(5,3,1,2,4)] # sort columns # melt the data frame for plotting data.m &lt;- melt(data, id.vars='Names') # plot everything ggplot(data.m, aes(Names, value)) + geom_bar(aes(fill = variable), position = "dodge", stat="identity") </code></pre> <p>Is this what you're after?</p> <p><img src="https://i.stack.imgur.com/zlAi2.png" alt="enter image description here"></p> <p>To clarify a little bit, in <a href="https://stackoverflow.com/questions/17303573/ggplot-multiple-grouping-bar">ggplot multiple grouping bar</a> you had a data frame that looked like this:</p> <pre><code>&gt; head(df) ID Type Annee X1PCE X2PCE X3PCE X4PCE X5PCE X6PCE 1 1 A 1980 450 338 154 36 13 9 2 2 A 2000 288 407 212 54 16 23 3 3 A 2020 196 434 246 68 19 36 4 4 B 1980 111 326 441 90 21 11 5 5 B 2000 63 298 443 133 42 21 6 6 B 2020 36 257 462 162 55 30 </code></pre> <p>Since you have numerical values in columns 4-9, which would later be plotted on the y axis, this can be easily transformed with <code>reshape</code> and plotted.</p> <p>For our current data set, we needed something similar, so we used <code>freq=table(col(raw), as.matrix(raw))</code> to get this:</p> <pre><code>&gt; data Names Very.Bad Bad Good Very.Good 1 Food 7 6 5 2 2 Music 5 5 7 3 3 People 6 3 7 4 </code></pre> <p>Just imagine you have <code>Very.Bad</code>, <code>Bad</code>, <code>Good</code> and so on instead of <code>X1PCE</code>, <code>X2PCE</code>, <code>X3PCE</code>. See the similarity? But we needed to <strong>create</strong> such structure first. Hence the <code>freq=table(col(raw), as.matrix(raw))</code>.</p>
 

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