Interactive plots

Basic

Mainly allows panning, zooming, highliting and tooltips (that pop up on hover).

gg1<-ggplot(aggDataOrg, aes(y=imbgeco, x=ppltrst, name=Country, color=Region))+
  geom_point() + xlab(varLabs["ppltrst"]) + ylab(varLabs["imbgeco"])
ggplotly(gg1, tooltip = "name")

Basic with custom tooltip

gg2<-ggplot(aggDataOrg, aes(y=imbgeco, x=ppltrst, text=paste0(Country,"<br> Trust: ",formatC(ppltrst, digits = 3), "<br> Immigration: ",formatC(imbgeco, digits = 3)), color=Region))+
  geom_point() + xlab(varLabs["ppltrst"]) + ylab(varLabs["imbgeco"])
ggplotly(gg2, tooltip = "text")

Basic interactive plot with highlighting groups and selectbox

One can also choose to highlight groups, or select things to highlight via menu. Of course, one could also choose just one.

aggDataOrgSD<-highlight_key(aggDataOrg,key=~Region)
gg3<-ggplot(aggDataOrgSD, aes(y=imbgeco, x=ppltrst, name=Country, color=Region))+
  geom_point() + xlab(varLabs["ppltrst"]) + ylab(varLabs["imbgeco"])
ggplotly(gg3, tooltip = "name") %>% highlight(on="plotly_hover", selectize = TRUE, )
## Setting the `off` event (i.e., 'plotly_doubleclick') to match the `on` event (i.e., 'plotly_hover'). You can change this default via the `highlight()` function.

Interactive tables

One can also choose to highlight groups, or select things to highlight via menu.

aggDataForm<-aggDataOrg %>% select(-cntry2)
tmpColnames<-colnames(aggDataForm)
tmpColnames[1:4]<-c("Country code", "Trust in people", "Immigration good or bad", "Happy")
DT::datatable(aggDataForm, colnames = tmpColnames) %>% formatRound(2:4)