I'm having trouble creating grouped barplots. Have explored base graphics and lattice.
My data looks like
compound detection LUtype
a 50 ag
a 75 urban
a 34 mixed
b 89 ag
......
I'd like to create a plot with compounds on the y axis (horizontal bar plot) with the bars colored to represent the land use type and detection on the x axis. These data are stored in a data frame, which I tried converting to a matrix with as.matrix, but this doesn't work and from what I can tell, the matrix is only the row of compounds. This does not produce a plot.
bars<-data.frame(data6$compound,data6$detection,data6$LUtype)
barsM<-as.matrix(data6$compound,data6$detection,data6$LUtype)
barplot(barsM,horiz=TRUE,beside=TRUE)
I also tried to bypass the matrix by using lattice, by no plot here either.
library(lattice)
require(lattice)
barchart(data6$detection~data6$compound,groups=data6$LUtype,bars)
I'm reading this article plotting grouped bar charts in R, and I have basically the same set up, but these solutions aren't working for me.