I have a dataframe with 3 columns
$x— at http://pastebin.com/SGrRUJcA$y— at http://pastebin.com/fhn7A1rj$z— at http://pastebin.com/VmVvdHEE
that I wish to use to generate a stacked barplot. All of these columns hold integer data. The stacked barplot should have the levels along the x-axis and the data for each level along the y-axis. The stacks should then correspond to each of $x, $y and $z.
UPDATE: I now have the following:
counted <- data.frame(table(myDf$x),variable='x')
counted <- rbind(counted,data.frame(table(myDf$y),variable='y'))
counted <- rbind(counted,data.frame(table(myDf$z),variable='z'))
counted <- counted[counted$Var1!=0,] # to get rid of 0th level??
stackedBp <- ggplot(counted,aes(x=Var1,y=Freq,fill=variable))
stackedBp <- stackedBp+geom_bar(stat='identity')+scale_x_discrete('Levels')+scale_y_continuous('Frequency')
stackedBp
which generates:
.
Two issues remain:
-
the x-axis labeling is not correct. For some reason, it goes: 46, 47, 53, 54, 38, 40…. How can I order it naturally?
-
I also wish to remove the 0th label.
I’ve tried using +scale_x_discrete(breaks = 0:50, labels = 1:50) but this doesn’t work.
NB. axis labeling issue: Dataframe column appears incorrectly sorted
Not completely sure what you’re wanting to see… but reading
?barplotsays the first argument,heightmust be a vector or matrix. So to fix your initial error:If you provide a reproducible example and a more specific description of your desired output you can get a better answer.
Or if I were to guess wildly (and use ggplot)…