cyl.am <- ggplot(mtcars, aes(x = factor(cyl), fill = factor(am)))
#(position = "stack" by default)
cyl.am + geom_bar()
# Fill - show proportion
cyl.am + geom_bar(position = "fill")
# Dodging - principles of similarity and proximity
cyl.am + geom_bar(position = "dodge") 
# Clean up the axes with scale_ functions
val = c("#E41A1C", "#377EB8")
lab = c("Manual", "Automatic")
cyl.am +
  geom_bar(position = "dodge") +
  scale_x_discrete("Cylinders") + 
  scale_y_continuous("Number") +
  scale_fill_manual("Transmission", 
                    values = val,
                    labels = lab) 
ggplot(mtcars, aes(x = mpg)) + geom_point() #Generates an error
ggplot(mtcars, aes(x = mpg, y = 0)) + geom_point()
ggplot(mtcars, aes(x = mpg, y = 0)) + geom_jitter()
#geom_jitter() - to avoid having all the points on a horizontal line
# Adding function to change y axis limits
ggplot(mtcars, aes(x = mpg, y = 0)) + geom_jitter() + scale_y_continuous(limits=c(-2,2))