0

In my dataset, the x-variable is a categorical variable called "Agency" which has 3 variables. I am trying to plot multiple Y variables called "Limitation 1, Limitation 2,...Limitation7" to make a single graph that contains all the y variables and the x variable at the bottom. Below is the sample code I used to get the individual bar graphs, but is there a code that enables me to merge the results from all the 7 categorical Y variables into one layout?

This is currently the code I am using to get individual bar graphs and I did this for all the limitations

counts7 <- table(dataset$Limitation1, dataset$Agency)

barplot(counts7,main="Limitation1 and Agency",                                                                                  
    xlab="HTA Agency", col=c("darkgrey","black")                                
    legend = rownames(counts), beside=TRUE)
  • Possible duplicate of [Plot two graphs in same plot in R](https://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r) – divibisan Jul 08 '19 at 22:33
  • It's hard to say without sample data or being able to see your output. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that's easier for folks to help with – camille Jul 09 '19 at 01:18

1 Answers1

0

It would help to have your data, and maybe a more detailed explanation of what you want, but here is a go using a slightly modified version of the inbuilt airquality data set. Using melt() from reshape2 to convert from wide to long representation (makes tabulation much easier), and barchart() from lattice to make the multi-way plot.

library(lattice)
library(reshape2)

airq <- airquality[, -6]
airq[,1:4] <- lapply(airq[,1:4], 
  function(x) cut(x, quantile(x, na.rm=TRUE), labels=1:4))

airq.tab <- table(melt(airq, id.vars="Month"))

barchart(airq.tab, stack=FALSE, layout=c(1, 4), horizontal=FALSE, xlab="Month")

enter image description here

AkselA
  • 8,153
  • 2
  • 21
  • 34