1 World Wildlife Trading Data Visiualization

1.1 Introduction

We will use the CITES Wildlife Trade Database in 2016 to visualize the countries Import and Export the most for wildLife products and how are they distributed. In addition, we will look the purpose of the Wild animal trading and how it related with different countries. Furthermore, we will figure out what is the most traded families. Finally, we will investigate Elephant trading.

1.1.1 Data Cleaning

We will categories the data by the purpose, and re-code the Exporter and Importer country data name. In addition, we will convert the unit, such as kg to g, L to ml.

# Recode the purpose

wild$ppose <- ifelse(wild$Purpose=="B", "Breeding",
              ifelse( wild$Purpose=="E", "Educational",
                 ifelse ( wild$Purpose=="G", "Garden",
                 ifelse( wild$Purpose=="H", "Hunting",
                 ifelse ( wild$Purpose=="L", "Law",
                ifelse ( wild$Purpose=="M", "Medical",
                 ifelse( wild$Purpose=="R", "reintroduction to wild",
                 ifelse ( wild$Purpose=="P", "Personal",
                 ifelse ( wild$Purpose=="Q", "Circus",
                 ifelse( wild$Purpose=="S", "Scientific",
                 ifelse ( wild$Purpose=="T", "Commercial",
                 ifelse ( wild$Purpose=="Z", "Zoo",
                            "Unknown"))))))))))))

# Recode country

wild$Excountry <- ifelse(wild$Exporter %in% c("CN", "HK"), "China",
                 ifelse( wild$Exporter=="US", "USA",
                 ifelse ( wild$Exporter=="AE", "Unite Arab Emirates",
                 ifelse( wild$Exporter=="BE", "Belgium",
                 ifelse ( wild$Exporter=="CZ", "Czech Republic",
                ifelse ( wild$Exporter=="NL", "Netherlands",
                 ifelse( wild$Exporter=="ID", "Indonesia",
                 ifelse ( wild$Exporter=="IT", "Italy",
                 ifelse ( wild$Exporter=="SG", "Singerpore",
                 ifelse( wild$Exporter=="MY", "Malaysia",
                 ifelse ( wild$Exporter=="JP", "Japan",
                 ifelse ( wild$Exporter=="MG", "Madagascar",
                 ifelse ( wild$Exporter=="FR", "France",
                 ifelse ( wild$Exporter=="DE", "Germany",
                          ifelse ( wild$Exporter=="GB", "Britain",
                 ifelse ( wild$Exporter=="PE", "Peru",
                ifelse ( wild$Exporter=="DE", "Germany",
                          ifelse ( wild$Exporter=="ES", "Spain",
                 ifelse ( wild$Exporter=="ZW", "Zimbabwe",
                  ifelse ( wild$Exporter=="PH", "Philippines",
                 ifelse ( wild$Exporter=="MC", "Monaco",
                           ifelse ( wild$Exporter=="IL", "Israel",
                  ifelse ( wild$Exporter=="AR", "Argentina",
                 ifelse ( wild$Exporter=="GT", "Guatemala",
                           ifelse ( wild$Exporter=="KW", "Kuwait",
                 ifelse ( wild$Exporter=="DK", "Denmark",
                            ifelse ( wild$Exporter=="UY", "Uruguay",
                 ifelse ( wild$Exporter=="GE", "Geogria",
                           ifelse ( wild$Exporter=="PL", "Poland",
                 ifelse ( wild$Exporter=="TN", "Tunisia",
                                 ifelse ( wild$Exporter=="KE", "Kenya",
                 ifelse ( wild$Exporter=="NO", "Norway",
                           ifelse ( wild$Exporter=="UG", "Uganda",
                 ifelse ( wild$Exporter=="MA", "Morocco",
                                   ifelse ( wild$Exporter=="BS", "Bahamas",
                 ifelse ( wild$Exporter=="NP", "Nepal",
                           ifelse ( wild$Exporter=="IN", "India",
                 ifelse ( wild$Exporter=="NI", "Nicaragua",
                                  ifelse ( wild$Exporter=="PY", "Paraguay",
                 ifelse ( wild$Exporter=="AM", "Armenia",
                                   ifelse ( wild$Exporter=="TH", "Thailand",
                 ifelse ( wild$Exporter=="CA", "Canada",
                                  ifelse ( wild$Exporter=="NG", "Nigeria",
                 ifelse ( wild$Exporter=="MX", "Mexico",
                          
                                       ifelse ( wild$Exporter=="CM", "Cameroon",
                 ifelse ( wild$Exporter=="FJ", "Fiji",
                                  ifelse ( wild$Exporter=="ZA", "South Africa",
                 ifelse ( wild$Exporter=="JM", "Jamaica",
                           ifelse ( wild$Exporter=="AD", "Andorra",
                            wild$Exporter)))))))))))))))))))))))))))))))))))))))))))))))))


wild$Imcountry <- ifelse(wild$Importer %in% c("CN", "HK"), "China",
                 ifelse( wild$Importer=="US", "USA",
                 ifelse ( wild$Importer=="AE", "Unite Arab Emirates",
                 ifelse( wild$Importer=="BE", "Belgium",
                 ifelse ( wild$Importer=="CZ", "Czech Republic",
                ifelse ( wild$Importer=="NL", "Netherlands",
                 ifelse( wild$Importer=="ID", "India",
                 ifelse ( wild$Importer=="IT", "Italy",
                 ifelse ( wild$Importer=="SG", "Singerpore",
                 ifelse( wild$Importer=="MY", "Malaysia",
                 ifelse ( wild$Importer=="JP", "Japan",
                 ifelse ( wild$Importer=="MG", "Madagascar",
                 ifelse ( wild$Importer=="FR", "France",
                 ifelse ( wild$Importer=="DE", "Germany",
                          ifelse ( wild$Importer=="GB", "Britain",
                 ifelse ( wild$Importer=="PE", "Peru",
                ifelse ( wild$Importer=="DE", "Germany",
                          ifelse ( wild$Importer=="ES", "Spain",
                 ifelse ( wild$Importer=="ZW", "Zimbabwe",
                  ifelse ( wild$Importer=="PH", "Philippines",
                 ifelse ( wild$Importer=="MC", "Monaco",
                                        ifelse ( wild$Exporter=="IL", "Israel",
                  ifelse ( wild$Importer=="AR", "Argentina",
                 ifelse ( wild$Importer=="GT", "Guatemala",
                           ifelse ( wild$Importer=="KW", "Kuwait",
                 ifelse ( wild$Importer=="DK", "Denmark",
                                           ifelse ( wild$Importer=="UY", "Uruguay",
                 ifelse ( wild$Importer=="GE", "Geogria",
                           ifelse ( wild$Importer=="PL", "Poland",
                 ifelse ( wild$Importer=="TN", "Tunisia",
                                 ifelse ( wild$Importer=="KE", "Kenya",
                 ifelse ( wild$Importer=="NO", "Norway",
                           ifelse ( wild$Importer=="UG", "Uganda",
                 ifelse ( wild$Importer=="MA", "Morocco",
                                   ifelse ( wild$Importer=="BS", "Bahamas",
                 ifelse ( wild$Importer=="NP", "Nepal",
                           ifelse ( wild$Importer=="IN", "India",
                 ifelse ( wild$Importer=="NI", "Nicaragua",
                                  ifelse ( wild$Importer=="PY", "Paraguay",
                 ifelse ( wild$Importer=="AM", "Armenia",
                                   ifelse ( wild$Importer=="TH", "Thailand",
                 ifelse ( wild$Importer=="CA", "Canada",
                                  ifelse ( wild$Importer=="NG", "Nigeria",
                 ifelse ( wild$Importer=="MX", "Mexico",
                          
                                       ifelse ( wild$Importer=="CM", "Cameroon",
                 ifelse ( wild$Importer=="FJ", "Fiji",
                                  ifelse ( wild$Importer=="ZA", "South Africa",
                 ifelse ( wild$Importer=="JM", "Jamaica",
                           ifelse ( wild$Importer=="AD", "Andorra",
                            wild$Importer)))))))))))))))))))))))))))))))))))))))))))))))))

#convert the unit
wild$exquantity <- ifelse(wild$Unit %in% c("kg", "L", "l"), wild$Exporter.reported.quantity*1000, wild$Exporter.reported.quantity)



wild$imquantity <- ifelse(wild$Unit %in% c("kg", "L", "l"), wild$Importer.reported.quantity*1000, wild$Importer.reported.quantity)

#total quantity
wild$allq <- rowSums(wild[, c("exquantity", "imquantity")], na.rm=TRUE)

1.2 Geographical Analysis for WildLife Trading

In this section, we will take the top 15 Export Country and Import Country for WildLife trading and see how are they are geographically distributed in the world. In our work, because the quanity unit is not specified for some entries. so this distribution is just a general guide, could be deviated from the truth.

1.2.1 Top 15 WildLife Export Country

We group the Export quantity by countries and select the top 15. China has the most Export then followed by Argentina. Overall, Most Developing countries have heavy export, such as China, India, Malaysia and Nepal in Asia. and some African and South American countries. To our surprise, USA, Norway and Singerpore is among the Top export countries. Western Europe doesnt have much trade.

i1 <- filter(wild,  exquantity >0 & !is.na(Exporter))
icountry <- group_by(i1, Excountry )
ic2 <- dplyr::summarise(icountry,  count=n(), add=sum(exquantity, na.rm=TRUE))
ic2 <- arrange(ic2, desc(add))
ic20 <- ic2[1:15,]

p1 <- ggplot(ic20, aes(x=reorder(Excountry,add),y=add))+
  geom_bar(aes(y=add,fill=add), stat="identity")+scale_fill_gradient(low="lightgrey", high="black")+
  labs(x="Country", y="Count",
       title="WildLife Export Country Top 15")+ theme(legend.position="none", axis.text.x = element_text(angle = 60, hjust = 1)) #+ scale_x_continuous(breaks=year2$year)
p1

n <- joinCountryData2Map(ic2, joinCode="NAME", nameJoinColumn="Excountry")
## 98 codes from your data successfully matched countries in the map
## 8 codes from your data failed to match with a country code in the map
## 158 codes from the map weren't represented in your data
mapCountryData(n, nameColumnToPlot="add", mapTitle=" WildLife Export Country Map" , colourPalette = "negpos8")

1.2.2 Top 15 WildLife Import Country

China won again for the country Import the most wildlife. In the overall distribution, we can see the most import trade comes from Asia, Western Europe and North America, and few countries in South America. Couple sporadic countries in Africa.

# group the country
e1 <- filter(wild,  imquantity >0 & !is.na(Imcountry))
ecountry <- group_by(e1, Imcountry )
ec2 <- dplyr::summarise(ecountry, add=sum(imquantity, na.rm=TRUE), count=n())
ec2 <- arrange(ec2, desc(add))
ec20 <- ec2[1:15,]

#barchart
p2 <- ggplot(ec20, aes(x=reorder(Imcountry,add),y=add))+
  geom_bar(aes(y=add,fill=add), stat="identity")+scale_fill_gradient(low="skyblue", high="darkblue")+
  labs(x="Country", y="Quantity",
       title="WildLife Import Country Top 25")+ theme(legend.position="none", axis.text.x = element_text(angle = 60, hjust = 1)) #+ scale_x_continuous(breaks=year2$year)
p2

# Geomap
n <- joinCountryData2Map(ec2, joinCode="NAME", nameJoinColumn="Imcountry")
## 75 codes from your data successfully matched countries in the map
## 9 codes from your data failed to match with a country code in the map
## 173 codes from the map weren't represented in your data
mapCountryData(n, nameColumnToPlot="add", mapTitle="Top WildLife Import Country World Map" , colourPalette = "rainbow")

1.2.3 Combined Import and Export

Now we take the countries in both Top Export and Top Import Countries.Then we add the amount of Export and Import quanity to be the total amount. From the graph, we can see China has the largest amount among the world. The main trading area is in Asia.

# change name

names(ec20)[names(ec20)=="count"]<- "count1"
names(ec20)[names(ec20)=="add"]<- "add1"
names(ec20)[names(ec20)=="Imcountry"]<- "c"
names(ic20)[names(ic20)=="Excountry"]<- "c"


comb1<-  merge(ec20, ic20, by="c")
comb2<- comb1 %>% mutate( t= add1+add)

#barchart
p3 <- ggplot(comb2, aes(x=reorder(c,t),y=t))+
  geom_bar(aes(y=t,fill=t), stat="identity")+scale_fill_gradient(low="#9999FF", high="violetred3")+
  labs(x="Country", y="Count",
       title="Top WildLife Import & Export Country")+ theme(legend.position="none", axis.text.x = element_text(angle = 60, hjust = 1)) #+ scale_x_continuous(breaks=year2$year)
p3

# Geomap
n2 <- joinCountryData2Map(comb2, joinCode="NAME", nameJoinColumn="c")
## 5 codes from your data successfully matched countries in the map
## 1 codes from your data failed to match with a country code in the map
## 238 codes from the map weren't represented in your data
mapCountryData(n2, nameColumnToPlot="t", mapTitle="Top WildLife Import & Export Country World Map" , colourPalette = "rainbow")

1.3 Visualiztion for WildLife Trading

1.3.1 The Purpose of WildLife Trading

Now we want to see the distribution of the purpose. From the Bar chart we can see the WildLife traded the most for Commerical usage. In addition, USA, Japan, China, Germany import the most for commerical use and Italy, France USA and China export the most for commerical usage. In addition, we grouped all the Purpose term and used the count method not the quanity. because many of the entries have missing value if we use quanity

# with purpose entries
cat1 <- filter(wild,!is.na(ppose))
cat1$sum <- rowSums(cat1[, c("exquantity", "imquantity")], na.rm=TRUE)

# group by purpose
cat1p <- group_by(cat1, ppose )
cat2p <- dplyr::summarise(cat1p, sum1=sum(sum), count=n())

#barchart
p4 <- ggplot(cat2p, aes(x=reorder(ppose,count),y=count))+
  geom_bar(aes(y=count,fill=ppose), stat="identity")+ scale_fill_brewer(palette="Set3")+
  labs(x="Purpose", y="count",
       title="WildLife Trading Purpose")+ theme(legend.position="none", axis.text.x = element_text(angle = 90, hjust = 1)) 
p4

# group by purpose and country
catc1 <- filter(wild, Excountry %in% c("USA","China","Thailand","Canada","Nigeria","Argentina","Mexico","Cameroon","Nicaragua","Indonesia","Fiji","South Africa","Paraguay",
                                       "India","Jamaica"))
cat1ecp <- group_by(catc1, Excountry,ppose )
cat2ecp <- dplyr::summarise(cat1ecp, sum2=sum(exquantity) , count=n())  

#tree map (didnt't work)
#treec<-treemapify(cat2ecp, area="count", fill="Excountry", label="ppose", group="ppose")

#heatmap


p5 <- ggplot(cat2ecp, aes(x=reorder(ppose,count),y=count))+
  geom_bar(aes(y=count,fill=Excountry), stat="identity")+
  labs(x="Purpose", y="Count",
       title="WildLife Trading Purpose For Export")+ theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1)) 
p5

#heat<- ggplot(cat2ecp, aes(Excountry, ppose))+geom_tile(aes(fill=count), colour="white")+ #scale_fill_gradient(low="cadetblue1", high="pink")
#heat+ theme_bw(base_size=9)+ labs(x="Purpse", y="Country", title="Wildlife Export Country Trading Heatmap")+ theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1)) 

We can see the Commercial Use is way higher than the other purpose, when we look into the countries, we find out Indonesia has the most count for Commerical usage, then China, USA and Thailand.

# Explore commerical use

cp <- filter(cat2ecp, ppose %in% c("Commercial"))

data <- cp[, c(1,4)]
data$id=seq(1, nrow(data))
label_data=data
number_of_bar=nrow(label_data)
angle= 90 - 360 * (label_data$id-0.5) /number_of_bar 
label_data$hjust<-ifelse( angle < -90, 1, 0)
label_data$angle<-ifelse(angle < -90, angle+180, angle)



p = ggplot(data, aes(x=as.factor(id), y=count))+geom_bar(stat="identity", fill=alpha("skyblue", 0.7)) + ylim(-1500,6500) +theme_minimal() +theme(
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
 plot.margin = unit(rep(-1,4), "cm")) +
coord_polar(start = 0) +geom_text(data=label_data, aes(x=id, y=count+10, label=Excountry, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2)
p 

#Import 
catc1i <- filter(wild, Imcountry %in% c("USA","China","Belgium","Britain","France","Germany","Italy","Japan","Netherlands","Argentina","Madagascar","Poland",
                                       "Singerpore","Spain","India"))
cat1icp <- group_by(catc1i, Imcountry,ppose )
cat2icp <- dplyr::summarise(cat1icp,  count=n()) 

cat2icpf <- filter(cat2icp, count>50)

p6 <- ggplot(cat2icpf, aes(x=reorder(ppose,count),y=count))+
  geom_bar(aes(y=count,fill=Imcountry), stat="identity")+
  labs(x="Purpose", y="Count",
       title="WildLife Import Trading Purpose For Import")+ theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1)) 
p6

# Import for Commerical
cpi <- filter(cat2icp, ppose %in% c("Commercial"))

data1 <- cpi[, c(1,3)]
data1$id=seq(1, nrow(data1))
label_data1=data1
number_of_bar1=nrow(label_data1)
angle1= 90 - 360 * (label_data1$id-0.5) /number_of_bar1 
label_data1$hjust<-ifelse( angle1 < -90, 1, 0)
label_data1$angle<-ifelse(angle1 < -90, angle1+180, angle1)



pi <- ggplot(data1, aes(x=as.factor(id), y=count))+geom_bar(stat="identity", fill=alpha("pink", 0.7)) + ylim(-2000,6500) +theme_minimal() +theme(
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
 plot.margin = unit(rep(-1,4), "cm")) +
coord_polar(start = 0) +geom_text(data=label_data1, aes(x=id, y=count+10, label=Imcountry, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2)+ggtitle("Wildlife Import Commerical use Country distribution")

pi1 <- pi+guides(fill=guide_legend(title="New Legend Title")) 
pi1

1.3.2 Terms of WildLife Trading

From the Treemap of WildLife trading terms, we selected the terms shows up more than 300 times in order get a general idea of what term human consumes the most. From the treemap can see more than half of the animal traded alive. Then followed by small leather products, which could be our leather bags or gentlemen’s belt. In addition, although Ivory Carving shows up a small square, it can only come from the elephants where other products can be obtained from different animals.

# with purpose entries
t1 <- filter(wild,!is.na(Term))

# group by Term
t1p <- group_by(t1, Term )
t2p <- dplyr::summarise(t1p,  count=n())
t2p <- filter(t2p, count>300)

# Term treemap
treemap(t2p, index="Term", vSize="count", type="index", 
        palette="Pastel2", title="WildLife Trade Term Treemap", fontsize.title=12)

1.3.3 WildLife Animal Trading Family

# with Family entries
fa1 <- filter(wild,!is.na(Family))

# group by Family
f1p <- group_by(fa1, Family)
f2p <- dplyr::summarise(f1p, a=sum(allq),  count=n())
f2p1 <- filter(f2p, count!=461)

test <- arrange(f2p1, desc(a))
test1 <- test[1:24,]

fp1t <- ggplot(test1, aes(x=reorder(Family,a),y=a))+
  geom_bar(aes(y=a,fill=a), stat="identity")+scale_fill_gradient(low="orange", high="red")+
  labs(x="Family", y="Count",
       title="WildLife Traded Family Top 24")+ theme(legend.position="none", axis.text.x = element_text(angle = 60, hjust = 1))
fp1t

#fp1 <- ggplot(f2p1, aes(x=reorder(Family,count),y=count))+
 # geom_bar(aes(y=count,fill=count), stat="identity")+scale_fill_gradient(low="orange", high="red")+
  #labs(x="Family", y="Count",
   #    title="WildLife Traded Family Top 24")+ theme(legend.position="none", axis.text.x = element_text(angle = 60, hjust = 1))
#fp1

1.4 Analysis on Top 5 Most traded Families

mfa1 <- filter(wild, Family %in% c("Orchidaceae", "Anguillidae", "Zygophyllaceae", "Araliaceae", "Leguminosae") )

# group by Family, ppose
mf1p <- group_by(mfa1, Family, ppose)
mf2p <- dplyr::summarise(mf1p,  a1=sum(allq),count=n())
mf2p1 <- filter(mf2p, count>20)

# circle plot

# Set a number of 'empty bar'


mdata1 <- mf2p1
mdata1$id=seq(1, nrow(mdata1))
mlabel_data1=mdata1
mnumber_of_bar1=nrow(mlabel_data1)
angle1m= 90 - 360 * (mlabel_data1$id-0.5) /mnumber_of_bar1 
mlabel_data1$hjust<-ifelse( angle1m < -90, 1, 0)
mlabel_data1$angle<-ifelse(angle1m < -90, angle1m+180, angle1m)

mp <- ggplot(mdata1, aes(x=as.factor(id), y=count, fill=Family))+geom_bar(stat="identity", alpha=0.5) + ylim(-4500,8800)+theme_minimal()+theme(
    axis.text = element_blank(),
    panel.grid = element_blank(),
    plot.margin = unit(rep(-1,6), "cm") 
  ) +
  coord_polar()+
  geom_text(data=mlabel_data1, aes(x=id, y=count+10, label=ppose, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= mlabel_data1$angle, inherit.aes = FALSE ) + ggtitle("d") 
 
mp

1.5 Elephant Analysis

1.5.1 Elephant

Elephant is one of my favorite animals. However, they are facing great danger now. As the Elephant Export graph shows, Zimbabwe export 500,000 for hunting. and Angentina imports a lot of elephants for Hunting as Well. From the tree map we can see, the main reason for Elephant product is Tusks. I hope from this analysis I can always remind for myself when I in a shop again. NO TRADE, NO KILLING !!!

ephant <- filter(wild, Family %in% c("Elephantidae") )

# group by excountry, ppose
ephant1 <- group_by(ephant, ppose, Exporter)
ephant2 <- dplyr::summarise(ephant1, a2=sum(exquantity, na.rm=TRUE), count=n())
ephant3 <- filter(ephant2, a2>1000)


ep1 <- ggplot(ephant3, aes(x=reorder(Exporter,a2),y=a2))+
  geom_bar(aes(y=a2,fill=ppose), stat="identity")+
  labs(x="Country", y="Export quantity",
       title="Elephant Export Purpose")+ theme( axis.text.x = element_text(angle = 60, hjust = 1))
ep1

# group by imcountry, ppose
ephant1i <- group_by(ephant, ppose, Importer)
ephant2i <- dplyr::summarise(ephant1i, a2=sum(imquantity, na.rm=TRUE), count=n())
ephant3i <- filter(ephant2i, a2>500)


ep1i <- ggplot(ephant3i, aes(x=reorder(Importer,a2),y=a2))+
  geom_bar(aes(y=a2,fill=ppose), stat="identity")+
  labs(x="Country", y="Import quantity",
       title="Elephant Import Purpose")+ theme( axis.text.x = element_text(angle = 60, hjust = 1))
ep1i

ephant11 <- group_by(ephant, Term, Excountry)
ephant21 <- dplyr::summarise(ephant11, a2=sum(allq), count=n())
treemap(ephant21, index="Term", vSize="a2", type="index", 
        palette="Greys", title="Elephant Trade Term Treemap", fontsize.title=12)

1.5.2 Elephant Confession

When I was really young, I got an ivory bracelet, I loved it so much that I have been wearing it for more than 20 years and never took it off. I always feel it is my guardian, like the elephants will protect me. When I grow older, I m proud of my ivory jelwery, because it is unique whereas others can get in stores and made by machines. Until couple days ago, I read a story, a small elephant starved himself to death in Wild Animal Helping Center RUNGWA, Tanzania because he saw how human killed his mother to take the ivory. I was very shocked that Ivory can only be taken alive from the elephants and in order to take it, the hunters have to cut its face alive. I can’t imagine how much pain the elephants have to take. It was then I felt so guilty I m one of the reason why elephant is extincting, I could not undo what it is done. But I won’t get any other piece of an ivory in my lifetime again. NO TRADE, NO KILLING!