Histograms and barchart with ggplot

library(ggplot2)
p <- ggplot(data = titanic,
            mapping = aes(x = Survived))
p + geom_bar(aes(y = ..count..))

titanic[, "cSurvived"] <- ""
titanic[titanic$Survived==1, "cSurvived"] <- "Survived"
titanic[titanic$Survived==0, "cSurvived"] <- "Died"


p <- ggplot(data = titanic,
            mapping = aes(x = cSurvived))
p + geom_bar(mapping = aes(y = ..count..), fill="tomato1") + xlab("")

p <- ggplot(data = titanic,
            mapping = aes(x = cSurvived, fill = as.factor(Pclass)))
p + geom_bar(mapping = aes(y = ..count..)) + xlab("")

p <- ggplot(data = titanic,
            mapping = aes(x = cSurvived, fill = as.factor(Pclass)))
p + geom_bar(position = "dodge",
             mapping = aes(y = ..prop.., group = Pclass)) + xlab("")

p <- ggplot(data = titanic,
            mapping = aes(x = cSurvived, fill = Pclass))
p + geom_bar(position = "dodge",
             mapping = aes(y = ..prop.., group = Pclass)) + xlab("")

p <- ggplot(data = titanic, 
            mapping = aes(x = Age))
p + geom_histogram(bins = 10)

p <- ggplot(data = titanic, 
            mapping = aes(x = Age, fill = Sex))
p + geom_histogram(alpha = 0.4, bins = 10)

p <- ggplot(data = titanic, 
            mapping = aes(x = Age, fill = Sex))
p + geom_histogram(alpha = 0.1, bins = 10, position = "identity")