<jupyter_start><jupyter_text>Database with one row for each publication-country association<jupyter_code>df <- read_csv("../5_Final_databases/output/database_multi_rows_each_paper_one_per_country.csv")
sprintf("%i x %i dataframe", nrow(df), ncol(df))<jupyter_output>Parsed with column specification:
cols(
  .default = col_double(),
  Country = [31mcol_character()[39m,
  title = [31mcol_character()[39m,
  ISO_3 = [31mcol_character()[39m,
  Region = [31mcol_character()[39m,
  authors = [31mcol_character()[39m,
  source = [31mcol_character()[39m,
  doi = [31mcol_character()[39m,
  abstract = [31mcol_character()[39m,
  author_keywords = [31mcol_character()[39m,
  model = [31mcol_character()[39m,
  scopus_number = [31mcol_character()[39m,
  WOS_number = [31mcol_character()[39m
)

See spec(...) for full column specifications.<jupyter_text>Get the list of topics ordered by descending topic representation<jupyter_code>topics_table <- read_csv("../4_Manual_treatment_topic_table/ouput/Table_topics.csv")
sprintf("%i x %i dataframe", nrow(topics_table), ncol(topics_table))
topics_table_ordered <- topics_table %>% 
                                arrange(desc(T0.02))
topics_list <- as.character(topics_table_ordered$Name)<jupyter_output><empty_output><jupyter_text>Function to create histogram per topic with the five countries most often associated to this topic<jupyter_code>plot_topic <- function(topic) {
    df_topic <- df %>% 
                dplyr::select(Country,Region,topic)%>%
                dplyr::group_by(Country)%>%
                dplyr::summarise(count = sum(!!sym(topic)),
                                 Region=first(Region))
    #dataframe with the five countries most often associated to the topic
    head_topic <- head(df_topic[order(-df_topic$count),],5) 
    head_topic <- data.frame(head_topic)
    #aggregation of all other countries
    row_other <- c("Others",sum(tail(df_topic[order(-df_topic$count),],132)$count),NA)
    head_topic[6,] <- row_other
    #rank column for apparition order in the graph (always row Other at the end)
    head_topic[,4] <- c(1,2,3,4,5,6)
    names(head_topic)[4] <- "Rank"
    head_topic$count <- as.double(head_topic$count)
    head_topic$Region <- factor(head_topic$Region,levels = c("Asia","Africa","Europe","European Union","North America", "Latin America","Oceania"))
    plot <- ggplot(data=head_topic, aes(x=reorder(Country,-Rank), y=count,fill=Region))+
            geom_bar(stat ="identity", width=0.9)+
            scale_fill_manual(values=c('Asia'='darkorange',
                                       'European Union'='#7CAE00',
                                       'Europe'='seagreen4',
                                       'North America'='dodgerblue',
                                       'Latin America'='cadetblue3',
                                       'Africa'='orchid',
                                       'Oceania'='coral2'),
                              na.value = 'dimgray',
                              drop = FALSE, 
                              label=c('Asia',
                                      'European Union',
                                      'Europe',
                                      'North America',
                                      'Latin America',
                                      'Africa',
                                      'Oceania',
                                      'Mix'))+
            coord_flip() +
            xlab("")+
            ylab("Nb of country-study asso")+
            ggtitle(topic) +
            theme_minimal() +
            theme(
                title = element_text(size = 18),
                legend.title = element_text(size = 18),
                legend.text = element_text(size = 16),
                axis.text.x = element_text(size = 16),
                axis.text.y = element_text(size = 16,face ="bold"),
                axis.title.x = element_text(size = 16, hjust = 0.5,face ="bold"),
                axis.title.y = element_text(size = 16, hjust = 0.5,face ="bold")
              )+
            geom_text(aes(label = count), size = 4, hjust = 1, vjust = 1) 
    return(plot)
    }
plot1 <- plot_topic(topics_list[1])
plot2 <- plot_topic(topics_list[2])
plot3 <- plot_topic(topics_list[3])
plot4 <- plot_topic(topics_list[4])
plot5 <- plot_topic(topics_list[5])
plot6 <- plot_topic(topics_list[6])
plot7 <- plot_topic(topics_list[7])
plot8 <- plot_topic(topics_list[8])
plot9 <- plot_topic(topics_list[9])
plot10 <- plot_topic(topics_list[10])
plot11 <- plot_topic(topics_list[11])
plot12 <- plot_topic(topics_list[12])
plot13 <- plot_topic(topics_list[13])
plot14 <- plot_topic(topics_list[14])
plot15 <- plot_topic(topics_list[15])
plot16 <- plot_topic(topics_list[16])
plot17 <- plot_topic(topics_list[17])
plot18 <- plot_topic(topics_list[18])
plot19 <- plot_topic(topics_list[19])
plot20 <- plot_topic(topics_list[20])
plot21 <- plot_topic(topics_list[21])
plot22 <- plot_topic(topics_list[22])
plot23 <- plot_topic(topics_list[23])
plot24 <- plot_topic(topics_list[24])
plot25 <- plot_topic(topics_list[25])
plot26 <- plot_topic(topics_list[26])
plot27 <- plot_topic(topics_list[27])
plot28 <- plot_topic(topics_list[28])
plot29 <- plot_topic(topics_list[29])
plot30 <- plot_topic(topics_list[30])
plot31 <- plot_topic(topics_list[31])
plot32 <- plot_topic(topics_list[32])
plot33 <- plot_topic(topics_list[33])
plot34 <- plot_topic(topics_list[34])
plot35 <- plot_topic(topics_list[35])
plot36 <- plot_topic(topics_list[36])
plot37 <- plot_topic(topics_list[37])
plot38 <- plot_topic(topics_list[38])
plot39 <- plot_topic(topics_list[39])
options(repr.plot.width=20, repr.plot.height=18)

plot1 <- ggarrange(plot1,plot2,plot3,plot4,
              plot5,plot6,plot7,plot8,
              plot9,plot10,plot11,plot12,
              plot13,plot14,plot15,plot16,
              plot17,plot18,plot19,plot20,
              common.legend = TRUE, legend = "top", ncol=4, nrow = 5,
              align = "v"
              )
plot1
plot2 <- ggarrange(plot21,plot22,plot23,plot24,
                   plot25,plot26,plot27,plot28,
                   plot29,plot30,plot31,plot32,
                   plot33,plot34,plot35,plot36,
                   plot37,plot38,plot39,
                   common.legend = TRUE, legend = "top", ncol=4, nrow = 5,
                   align ="v"
                  )
plot2
ggsave('./output/Fig_SI3_topics_countries1.png', height=20, width=18, plot=plot1)
ggsave('./output/Fig_SI4_topics_countries2.png', height=20, width=18, plot=plot2)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup