I have a dataset that looks something like this:
testSet <- data.table(date=as.Date(c("2013-07-02","2013-08-03","2013-09-04",
"2013-10-05","2013-11-06")),
yr = c(2013,2013,2013,2013,2013),
mo = c(07,08,09,10,11),
da = c(02,03,04,05,06),
plant = LETTERS[1:5],
product = letters[26:22],
rating = runif(5))
What I would like to do is plot 2 graphs using ggplot2.
The first would give me a dodged, continuous bar chart for all months that would have the product on the x, the ratings on the y, and the dates grouped and plotted on their respective products.
x = product
y = rating
Dodge = date
The second that I'm trying to create is a dodged, continuous bar chart for one month that would have the plant on the x, the ratings on the y, and the product grouped and plotted on their respective plants.
x = plant
y = rating
Dodge = product
I'm looking for an output that is very similar to this: http://docs.ggplot2.org/0.9.3/geom_bar-28.png but continuous.
I've had issues trying to figure out how the levels things works and haven't seen an example of a dodged, continuous chart.
Here is the code I have created so far:
testMean <- tapply(testSet$rating, list(testSet$mo), mean)
testLevels <- factor(levels(testSet$product,testSet$mo),
levels = levels(testSet$product,testSet$mo))
qplot(testLevels, aes(testMean, fill=cut)) +
geom_bar(position="dodge", stat="identity")
This is what the ggplot2 site says about creating a continuous bar chart, but it doesn't say anything about how to do it with multiple graphs overlayed on top of each other and then dodged, like in the one I linked to earlier. Here is their code:
meanprice <- tapply(diamonds$price, diamonds$cut, mean)
cut <- factor(levels(diamonds$cut), levels = levels(diamonds$cut))
qplot(cut, meanprice)
I appreciate the help, guys!
levels(), but it does not make sense. What were you hoping fortestLevelsto be? Also, it appears you are confusingdata.tablewithdata.frame- Ricardo Saporta