Thread for practice questions for Gov 1005 today

This thread will be used by students in Gov 1005 to post practice questions today. These are not actual questions! Please don't spend anytime answering them. Big thanks to Mara Averick for visiting us!

2 Likes
x %>% 
  group_by(course_department) %>% 
  summarize(avg = mena(u_grad))
#> Error in x %>% group_by(course_department) %>% summarize(avg = mena(u_grad)): could not find function "%>%"

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

difference <- joined_enroll %>% mutate(diff_ugrad = (u_grad_24-u_grad_17)) %>% arrange(desc(diff_ugrad)) %>% head(1) %>% select(course_name_24, diff_ugrad)
#> Error in joined_enroll %>% mutate(diff_ugrad = (u_grad_24 - u_grad_17)) %>% : could not find function "%>%"

difference
#> Error in eval(expr, envir, enclos): object 'difference' not found

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

image

Hi CianStryker, you pasted in a screenshot of your reprex. When you reprex was created, it should have added that text to your machine's clipboard. Meaning after your reprex() command, all you need to do is paste into this thread.

Hi sophiafreuden, it looks like you pasted in a screenshot of your reprex instead of the text that creates that. WHen you ran reprex(), it actually stored that text to your clipboard.

Here's the part of Jenny Bryan's video intro on how this works.

enroll17 %>% 
  select(course_name, withdraw, total) %>% 
  arrange(desc(withdraw))
#> Error in enroll17 %>% select(course_name, withdraw, total) %>% arrange(desc(withdraw)): could not find function "%>%"

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

1 Like
highestgov <- enrollment %>%
  select(course_name, course_department, total) %>%
  filter(course_department == "Government") %>%
  arrange(desc(total)) %>%
  head(10)
#> Error in enrollment %>% select(course_name, course_department, total) %>% : could not find function "%>%"
view(highestgov)
#> Error in view(highestgov): could not find function "view"

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

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

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

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

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

x <- gapminder %>% filter(year == 1962, continent != "Oceania", continent != "Europe")
#> Error in gapminder %>% filter(year == 1962, continent != "Oceania", continent != : could not find function "%>%"

ggplot(x, aes(x = gdpPercap, y = lifeExp, color = country, size = pop)) + geom_point() + guides(color = FALSE) + facet_wrap(~continent) + scale_x_log10() + labs(title = "The World in 1962", x = "GDP per capita", y = "Life Expectancy") + scale_x_discrete(breaks)
#> Error in ggplot(x, aes(x = gdpPercap, y = lifeExp, color = country, size = pop)): could not find function "ggplot"

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

gapminder %>%
  filter(continent = "Europe") %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) + geom_point() + transition_time(year) + labs(title = "Year: {time= frame_time}", x = "GDP per capita", y = "Life Expectancy") + scale_x_log1()
#> Error in gapminder %>% filter(continent = "Europe") %>% ggplot(aes(x = gdpPercap, : could not find function "%>%"

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

Please help me.

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

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

library(gapminder)
library(tidyverse)
library(reprex)

gapminder %>% 
  filter(year == 1962) %>%
  filter(continent == "Americas" | continent == "Africa" | continent == "Asia") %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, color = continent, size = pop)) +
  facet_wrap(facets = "continent") +
  scale_x_log10(breaks = c(0, 1,000, 10,000), labels = c("$1,000", "$10,000")) +
  labs(title = "The World Gets Better Every Year:",
       x = "GDP Per Capita",
       y = "Life Expectancy",
       caption = "Source: gapminder package") +
  geom_point()
#> Error: `breaks` and `labels` must have the same length

ggplot(data_1962, aes(x = gdpPercap, y = lifeExp, size = pop,
color = continent, group = country)) + geom_point(alpha = 0.4) +
facet_wrap(~continent) + scale_x_log10(labels = c("$1,000",
"$10,000"), breaks = c(1000, 10000)) + labs(x = "GDP Per Capita",
y = "Life Expectancy") + scale_fill_gradient(name = country)
#> Error in ggplot(data_1962, aes(x = gdpPercap, y = lifeExp, size = pop, : could not find function "ggplot"

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

gapminder %>% filter(year == 1962) %>% filter(continent != "Europe", continent != "Oceania") %>% ggplot(aes(x = gdpPercap, y = lifeExp, size = pop, color = country)) + geom_point(show.legend = FALSE) + scale_x_log10() facet_wrap(~continent) + labs(title = "The World Gets Better Every Year: 1969", y = "Life Expectancy", x = "GDP Per Capita")

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

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

  geom_point(color="red")
#> Error in geom_point(color = "red"): could not find function "geom_point"

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

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)