Thread for practice questions for Gov 1005 today

gapminder %>%
  filter(year == 1962) %>%
  filter(continent == c("Americas", "Africa", "Asia")) %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) +
  geom_point() +
  facet_wrap(~continent) +
  scale_x_log10() 
#> Error in gapminder %>% filter(year == 1962) %>% filter(continent == c("Americas", : could not find function "%>%"
  labs(title = "World in  1962",
       x = "GDP Per Capita", 
       y = "Life Expectancy")
#> Error in labs(title = "World in  1962", x = "GDP Per Capita", y = "Life Expectancy"): could not find function "labs"

Created on 2019-09-26 by the reprex package (v0.3.0)

gapminder %>%
  filter(year == 1962) %>%
  filter(continent == "Europe") %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) + 
  geom_point() +
  scale_x_log10() +
  labs( title = "World in 1962",
        x = "GDP per capita",
        y = "life Expectancy")
#> Error in gapminder %>% filter(year == 1962) %>% filter(continent == "Europe") %>% : could not find function "%>%"
gapminder %>% 
  filter(year ==1962) 
#> Error in gapminder %>% filter(year == 1962): could not find function "%>%"
  ggplot(aes(x= gdpPercap, y = lifeExp,size = pop, color = continent)) +
  geom_point() +
  scale_x_log10() +
  labs(title="GDP per capita vs life expectancy",
       x= "GDP per capita",
       y= "Life Expectancy") +
  facet_wrap(~continent)
#> Error in ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = continent)): could not find function "ggplot"

Created on 2019-09-26 by the reprex package (v0.3.0)

knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(gapminder)


gapminder %>% 
    filter(year == 1972, continent != "Europe", continent != "Oceania") %>% 
    ggplot(aesx = gdpPercap, y = lifeExp, size = pop) + 
           geom_point() +
           scale_x_log10() +
           facet_wrap(~ continent) +
           labs(title = "The World in 1972", x = "GDP Per Capita", y = "Life Expectancy")
#> Error: geom_point requires the following missing aesthetics: x, y
gapminder %>% 
  filter(year == 1972, continent != "Oceania", continent != "Europe") %>% 
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) + 
  geom_point() + 
  scale_x_log10() +
  facet_wrap(~continent) + 
  labs(title = "The World in 1972", x = "GDP Per Capita", y = "Life Expectancy")
#> Error in gapminder %>% filter(year == 1972, continent != "Oceania", continent != : could not find function "%>%"

data <- gapminder %>%
filter(country == "Belgium" & year == "1962")
#> Error in gapminder %>% filter(country == "Belgium" & year == "1962"): could not find function "%>%"

gapminder %>% 
  filter(year == 1962, continent = "Oceania", continent != "Europe")  %>% 
  ggplot(aes(x = gdpPercap, y = lifeExp, color = country, size = pop)) + 
    geom_point() + 
    facet_wrap(~continent) +
    scale_x_log10() +
    guides(color = FALSE, size = FALSE) +
    labs(title = "The World in 1962", 
         x = "GDP Per Capita", 
         y ="Life Expectancy") 
#> Error in gapminder %>% filter(year == 1962, continent = "Oceania", continent != : could not find function "%>%"
ggplot(Data, aes(x = gdpPercap, y = lifeExp, size = pop, color = pop)) +
  geom_point() +
  labs(title = "Europe in 1962", 
       x = "GDP Per Capita",
       y = "Life Expectancy") + 
    ylim(20, 80) 
#> Error in ggplot(Data, aes(x = gdpPercap, y = lifeExp, size = pop, color = pop)): could not find function "ggplot"
    scale_x_log10()
#> Error in scale_x_log10(): could not find function "scale_x_log10"
ggplot(lifeExp_62, aes(x=gdpPercap, y=lifeExp, size=pop)) + 
  geom_point() + 
  facet_wrap(~continent) + 
  scale_x_log10() +
  labs(title = "The World Keeps Gets Better Every Year: 1962") +
  xlab("GDP Per Capita") +
  ylab("Life Expectancy") +
  theme(legend.poition = "none")
#> Error in ggplot(lifeExp_62, aes(x = gdpPercap, y = lifeExp, size = pop)): could not find function "ggplot"

Created on 2019-09-26 by the reprex package (v0.3.0)

gapminder %>%
  filter(year == 1962, continent %in% c("Asia", "Africa", "Americas")) %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop)) %>%
  geom_point() +
  facet_wrap(~ continent) +
  labs(x = "GDP per capita", y = "Life Expectancy", title = "World in 1962") +
  scale_x_log10()
#> Error in gapminder %>% filter(year == 1962, continent %in% c("Asia", "Africa", : could not find function "%>%"

Created on 2019-09-26 by the reprex package (v0.3.0)

gapminder %>% 
  filter(continent == "Americas" | continent == "Africa" | continent == "Asia") %>% 
  
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) +
  geom_point(alpha = .5, show.legend = FALSE) +
  labs(x = "GDP Per Capita",
       y = "Life Expectancy") +
  scale_x_log10(labels = dollar) +
  facet_wrap(~continent) +
  transition_states(year,
                    transition_length = 5,
                    state_length = 1) +
    ggtitle('The World Gets Better Every Year: {closest_state}')
#> Error in gapminder %>% filter(continent == "Americas" | continent == "Africa" | : could not find function "%>%"
gapminder %>%
  filter(year == 1962 & continent %in% c("Americas", "Africa", "Asia")) %>%
  
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = continent)) +
  geom_point() +
  scale_x_log10(breaks = c(1000, 10000), label = c("$1000", "$10000")) +
  scale_y_continuous(limits = c(20, 85), breaks = c(40, 60, 80)) +
  scale_color_manual(values = c("orange", "red", "purple")) +
  facet_wrap(~ continent) +
  labs(title = "World in 1962",
       x = "GDP per capita",
       y = "Life Expectancy") +
  theme(legend.position = "none")
#> Error in gapminder %>% filter(year == 1962 & continent %in% c("Americas", : could not find function "%>%"

Created on 2019-09-26 by the reprex package (v0.3.0)

gapminder %>% filter(year == 1962) %>% ggplot(aes(x = gdpPercap, 
    y = lifeExp, size = pop, color = continent, alpha = pop)) + 
    geom_point() + scale_x_log10() + labs(title = "The World Gets Better Every Year", 
    x = "GDP per capita", y = "Life Expectancy") + facet_wrap(~continents)
#> Error in gapminder %>% filter(year == 1962) %>% ggplot(aes(x = gdpPercap, : could not find function "%>%"

Created on 2019-09-26 by the reprex package (v0.3.0)

gapminder%>%filter(country=="Belgium",year=="1962")
#> Error in gapminder %>% filter(country == "Belgium", year == "1962"): could not find function "%>%"

gapminder %>%
filter(year == 1962, continent %in% c("Africa" , "Asia", "Americas")%>%
ggplot(aes(x = gdpPercap, y = lifeExp, size = pop))+
geom_point()+
labs(title = "World in 1962", x = "GDP Per Capita", y = "Life Expectancy")+
scale_x_log10()+
facet_wrap(~ continent)

bel_1962 <- gapminder %>%
                filter (country == "Belgium", year == "1962") 
#> Error in gapminder %>% filter(country == "Belgium", year == "1962"): could not find function "%>%"
1 Like
gapminder  %>% filter(continent == "Americas") %>% filter(continent == "Africa") %>% filter(continent == "Asia") %>%  
  
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) +
  geom_point() +
  scale_x_log10() +
  labs(title = "World in 1962",
      x = "GDP per capita",
      y = "Life Expectancy") +
  facet_wrap(~ continent)
#> Error in gapminder %>% filter(continent == "Americas") %>% filter(continent == : could not find function "%>%"

Created on 2019-09-26 by the reprex package (v0.3.0)

1 Like
ggplot(gapminder%>%filter(continent %in% c("Asia", "Americas", "Africa")), aes(x=gdpPercap, y = lifeExp, size = pop))+facet_wrap(cantinent)+geom_point()+scale_x_log10()+scale_y_log10()+labs(x = "GDP per capita", y = "Life expectancy")
#> Error in ggplot(gapminder %>% filter(continent %in% c("Asia", "Americas", : could not find function "ggplot"

Created on 2019-09-26 by the reprex package (v0.3.0)

1 Like
gapminder %>%
  filter(year == "1962", continent %in% c("Africa", "Americas", "Asia")) %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = continent))
#> Error in gapminder %>% filter(year == "1962", continent %in% c("Africa", : could not find function "%>%"
  geom_point() +
  scale_x_log10("GDP Per Capita", breaks = c(1000, 10000)) +
  scale_y_continuous("Life Expectancy", limits = c(20, 85), breaks = c(40, 60, 80)) +
  labs(title = "World in 1962") +
  facet_wrap(~continent) +
  theme(legend.position = "none")
#> Error in geom_point(): could not find function "geom_point"
1 Like