The code below will create a Cleveland-style dot plot using the Dimple D3 library that shows the top 10 banana-exporting countries in 2011 by volume in metric tonnes.
library(rCharts)
library(dplyr)
library(FAOSTAT)
library(countrycode)
df <- getFAO(name = "Volume",
domainCode = "TP",
elementCode = 5910,
itemCode = 486)
df$Country <- countrycode(df$FAOST_CODE, "fao", "country.name")
banana_df <- df %>%
filter(FAOST_CODE < 5000, Year == 2011, !is.na(Country)) %>%
select(Country, Volume) %>%
filter(min_rank(desc(Volume)) < 11) %>%
arrange(Volume) %>%
mutate(Country = gsub("Dominican Republic", "Domin. Rep.", Country))
b <- dPlot(
x = 'Volume',
y = 'Country',
data = banana_df,
type = 'bubble')
b$xAxis(type = "addMeasureAxis")
b$yAxis(type = "addCategoryAxis", orderRule = 'Volume')
b$defaultColors(c("gold", "gold"))
b$show('iframesrc', cdn = TRUE)