Introduction
Questions
Variation
Visualizing distributions
ggplot(data = myData) +
geom_bar(mapping = aes(x = country))

myData %>% count(country)
## # A tibble: 7 × 2
## country n
## <chr> <int>
## 1 CHINA 45
## 2 FRANCE 210
## 3 INDIA 3
## 4 PAKIST 2
## 5 UK 45
## 6 USA 1032
## 7 USSR 714
ggplot(data = myData) +
geom_histogram(mapping = aes(x = latitude))
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

ggplot(data = myData, mapping = aes(x = latitude, colour = country)) +
geom_freqpoly()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

Typical values
myData %>%
filter(!is.na(latitude)) %>%
ggplot(aes(x = latitude)) +
geom_histogram(binwidth = 0.1)

# Wider bin to compare
myData %>%
ggplot(aes(latitude)) +
geom_histogram(binwidth = 0.5)

Unusual values
myData %>%
ggplot(aes(x = latitude)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

myData %>%
ggplot(aes(x = latitude)) +
geom_histogram() +
coord_cartesian(ylim = c(0, 50))
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

Missing values
myData %>%
# Only impossible latitudes become NA (valid range is -90 to 90)
mutate(latitude = ifelse(latitude < -90 | latitude > 90, NA, latitude)) %>%
ggplot(aes(x = longitude, y = latitude)) +
geom_point()

Covariation
A categorical and continuous variable
myData %>%
ggplot(aes(x = country, y = latitude)) +
geom_boxplot() +
coord_flip()
