# 2. Select graphs

# 2.1.  Countries with more than 100 companies
gg_q1_1 <- df_q1() %>% 
  filter(sum > 100) %>% 
  ggplot(aes(reorder(country, sum), sum, fill=factor(sum))) +
  ggtitle("Countries with more than 100 companies") +
  ylab("Number of companies") +
  xlab("Countries") +
  geom_bar(stat="identity") +
  scale_fill_discrete(name = "Number") +
  coord_flip()

# 2.2. Countries with 10-100 companies
gg_q1_2 <- df_q1() %>% 
  filter(sum %in% 10:100) %>% 
  ggplot(aes(reorder(country, sum), sum, fill=factor(sum))) +
  ggtitle("Countries with 10-100 companies") +
  xlab("Countries") +
  ylab("Number of companies") +
  geom_bar(stat="identity") +
  scale_fill_discrete(name = "Number") +
  theme_bw() +
  coord_flip()

# 2.3. Countries with 1-10 companies
gg_q1_3 <- df_q1() %>% 
  filter(sum %in% 1:10) %>% 
  ggplot(aes(reorder(country, sum), sum, fill=factor(sum))) +
  ggtitle("Countries with 1-10 companies") +
  xlab("Countries") +
  ylab("Number of companies") +  
  geom_bar(stat="identity") +
  scale_fill_discrete(name = "Number") +
  coord_flip()

# Select graph
if(input$q1_choice == "> 100"){ g <- gg_q1_1 }
if(input$q1_choice == "10-100"){ g <- gg_q1_2 }
if(input$q1_choice == "1-10"){ g <- gg_q1_3 }
