I want to create a barplot with 2 factors and 1 continuous variable for y. Μy code is (it is based on the build-in dataset: mtcars):
data(mtcars)
x=mtcars
library(ggplot2)
ggplot(x,aes(x=factor(carb), y=mpg, fill=factor(carb)))
+geom_bar(stat="summary",fun.y="mean")
+labs(title="Barplot of Average MPG per Carbon category per # of Cylinders", y="Mean MPG",x="Carbon Category")
+facet_grid(.~factor(cyl))
+geom_text(aes(label=mpg),vjust=3)
My goal is to have (and show) the average MPG value per carbon category, per cylinder category. Is my code correct?
The main problem is, I just want the mean value shown on each bar, not all values for this combination of factor values.
For example:
subset(x,c(x$carb==3 & x$cyl==8)) returns 3 different values for MPG, and the graph shows all these three!

