for variable population
# Step 1: With 3 key components (data, mapping, geom_)
ggplot(data = crime, mapping = aes(x = population)) + geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 2
ggplot(data = crime, mapping = aes(x = population)) + geom_histogram(fill = "blue")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 3
ggplot(data = crime, mapping = aes(x = population)) + geom_histogram(fill = "blue", col = "white")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 4
ggplot(data = crime, mapping = aes(x = population)) +
geom_histogram(fill = "blue", col = "white", aes(y = ..density..)) +
geom_density(col = "red")
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 5: Add main title for this graph
ggplot(data = crime, mapping = aes(x = population)) +
geom_histogram(fill = "blue", col = "white", aes(y = ..density..)) +
geom_density(col = "red") +
ggtitle("Distribution of population")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 6: Center alignment for the main title
ggplot(data = crime, mapping = aes(x = population)) +
geom_histogram(fill = "blue", col = "white", aes(y = ..density..)) +
geom_density(col = "red") +
ggtitle("Distribution of population") +
theme(plot.title = element_text(hjust = 0.5))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

# Step 7: I would like to change to the economist theme
ggplot(data = crime, mapping = aes(x = population)) +
geom_histogram(fill = "blue", col = "white", aes(y = ..density..)) +
geom_density(col = "red") +
ggtitle("Distribution of population") +
theme(plot.title = element_text(hjust = 0.5)) +
theme_economist() # this theme from library(ggthemes)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

for variable police
ggplot(crime, aes(police)) + geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(crime, aes(police)) + geom_histogram(fill = "blue")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(crime, aes(police)) + geom_histogram(fill = "blue", col = "white")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

ggplot(data = crime, aes(x = police)) +
geom_histogram(aes(y = ..density..), fill = "blue", col = "white", binwidth = 0.05) +
geom_density(col = "red")

ggplot(data = crime, aes(x = police)) +
geom_histogram(aes(y = ..density..), fill = "blue", col = "white", binwidth = 0.05) +
geom_density(col = "red") +
ggtitle("Distribution of the number of police")

ggplot(data = crime, aes(x = police)) +
geom_histogram(aes(y = ..density..), fill = "blue", col = "white", binwidth = 0.05) +
geom_density(col = "red") +
ggtitle("Distribution of the number of police") +
theme(plot.title = element_text(hjust = 0.5))

ggplot(data = crime, aes(x = police)) +
geom_histogram(aes(y = ..density..), fill = "blue", col = "white", binwidth = 0.05) +
geom_density(col = "red") +
ggtitle("Distribution of the number of police") +
theme(plot.title = element_text(hjust = 0.5)) +
theme_bw()

ggplot(data = crime, aes(x = police)) +
geom_histogram(aes(y = ..density..), fill = "blue", col = "white", binwidth = 0.05) +
geom_density(col = "red") +
ggtitle("Distribution of the number of police") +
theme(plot.title = element_text(hjust = 0.5)) +
theme_economist() # I need the economist theme in the "ggthemes" library
