Load Libraries

library(plotly)
library(dplyr)

Load data

Data used in this example is taken from the Model with ID 317.

load("data model 317/data_TM.RData")
load("data model 317/meta_TM.RData")
meta$mde7[which(meta$title=="NDC European Union")]<-"Europe"
#load("data model 317/dtm_TM.RData")

Topic Labeling

Use of Topic Labels as suggested by Chris Höhne.

topic_labels<-c("Topic 1: Adaptation governance",
                "Topic 2: Emission metrics and pledges",
                "Topic 3: (Renewable) energy and transport",
                "Topic 4: Water-related climate change vulnerability & impacts",
                "Topic 5: Domestic climate governance",
                "Topic 6: Economic issues",
                "Topic 7: UNFCCC governance and collaboration",
                "Topic 8: International support for developing countries",
                "Topic 9: Adaptation sectors and vulnerability",
                "Topic 10: Forest-related issues and actions",
                "Topic 11: Beef agriculture and alternative normative understandings",
                "Topic 12: Emission metrics and pledges and market mechanisms",
                "Topic 13: Agricultural issues and development projects",
                "Topic 14: Energy- and traffic-related issues and climate mitigation",
                "Topic 15: Rural and (post-) war issues")

Split by continents

continents<-unique(meta$mde7)
document_ids_per_continent<-lapply(continents,FUN = function(x){
  which(meta$mde7==x)
})

topic_distributions_per_continent<-lapply(X = document_ids_per_continent,FUN = function(x){
  theta[x,]
})

Create Boxplot per Continent

i=1
y<-c(rep(topic_labels,each=nrow(topic_distributions_per_continent[[i]])))
x<-topic_distributions_per_continent[[i]]
x<-c(x)
fig<- plot_ly(x=x,y=y,name=continents[i],type = "box")

for(i in 2:length(continents)){
  y<-c(rep(topic_labels,each=nrow(topic_distributions_per_continent[[i]])))
  x<-topic_distributions_per_continent[[i]]
  x<-c(x)
  fig<-add_trace(p = fig,x=x,y=y,name=continents[i])
}

fig<-layout(fig,xaxis=list(zeroline=F),boxmode="group")
fig

Fullscreen Boxlot on whole Screen

replication of the hsu paper plot

i=1
x<-unlist(lapply(1:15,FUN = function(x){
  mean(topic_distributions_per_continent[[i]][,x]) 
}
)
)
y<-topic_labels
fig2<-plot_ly(x=x,y=y,type="scatter",marker=list(size=13),name=continents[i])

for(i in 2:length(continents)){
  x<-unlist(lapply(1:15,FUN = function(x){
    mean(topic_distributions_per_continent[[i]][,x]) 
  }
  )
  )
  y<-topic_labels
 fig2<-add_trace(p = fig2, x=x,y=y,name=continents[i]) 
}

fig2

Fullscreen Replication of Hsu Plot