read.csv()
)dplyr
function (filter()
, summarize()
, etc.)dplyr
and ggplot2
dplyr
and ggplot2
.
ggplot()
aes()
geom_line()
geom_bar()
geom_smooth()
geom_point()
geom_boxplot()
geom_smooth()
facet_grid()
facet_wrap()
scale_manual()
lims()
labs()
guide_legend()
theme()
How do I…
dplyr
ggplot2
help()
, vignette tutorials, and online documentationdplyr
and ggplot2
dplyr
and ggplot2
data.frame
, graphic) corresponding to
the desired code solution.dplyr
review will be necessary (15 min allotted below)read.csv()
)str()
, head()
)dplyr
Recapselect()
filter()
group_by()
summarize()
Africa <- filter(data, continent=="Africa")
A. 5
B. 38
C. 52
D. 142“Make a data.frame
that stores the count of countries per continent?”
count_countries <- data %>%
group_by(continent) %>%
summarize(countries = n())
> count_countries
Source: local data frame [5 x 2]
continent countries
(fctr) (int)
1 Africa 52
2 Americas 25
3 Asia 33
4 Europe 30
5 Oceania 2
ggplot
: Grammar of GraphicsParsons Problem with components and form of ggplot2
geom_histogram() +
labs(x = "Log10( 2007 Population )", y = "Count")
ggplot(Africa, aes(log10(pop_2007))) +
geom_histogram()
, geom_density()
Faded Problem
ggplot(Africa, aes(________, ..count..)) +
geom_density() ________
labs(x = "Log10(________)", y = "Count")
labs()
theme()
Faded Problem Continued
ggplot(________) +
________ +
labs(________, y = "Count") +
theme_classic(base_size = 24, base_family = ________) +
theme(axis.title = element_text(size = 36))
geom_point()
, geom_smooth()
scale_manual()
Parsons Problem with blanks
ggplot(data, aes(x = ________, y = ________, size = pop_2007)) +
geom_point() +
theme_classic()
geom_smooth() +
labs(x = ________, y = ________, size = "Population", title = "2007") +
Faded Problem
ggplot(data, aes(________)) +
geom_smooth(method = ________, color = "black", size = 2) +
geom_point() +
scale_size(range = c(________)) +
scale_x_log10() +
labs(x = "GDP/capita [adjusted US$]", y = "Life Expectancy [years]",
size = "Population [millions]", title = "2007") +
theme_classic(________) +
theme(axis.title = ________)
Faded Problem: get data.frame
near to ‘Faceted Table’
pop_by_continent <- ________ %>%
gather(year, population, ________) %>%
separate(________, c("pop", "year"), sep = "_") %>%
select(continent, country, ________, ________)
Faded Problem: subset data for 2007
pop_2007 <- filter(________)
facet_grid()
lims()
Fix the Code
ggplot(pop_2007, aes(year)) +
geom_histogram(binwidth=0.5) +
scale_x_log10(limits = c(0.1, 10))
facet_grid(continent ~ .) +
labs(x = Population [millions], y = Number of countries,
title = "2007") +
theme_bw(base_size = 42, base_family = "Script") +
theme(axis.title=element_text(size=36))
geom_line()
, geom_area()
guide_legend()
geom_line()
to
geom_area()
and add labels and theme layers.ggplot2