This is a re-creation of the elevational graph of species published in “Distributional Patterns of Amphibians and Reptiles in Ghandruk, Annapurna Conservation Area, Nepal” using the same dataset.
Note that I did not create the graph for the article. However, I did create the map for the article and the authors acknowledged my contribution in their acknowledgement section.
Importing the dataset
setwd("D:/Rfiles/Chart_Bivek/ElevationGraph") # Setting the working directory
library(readxl)
if (!require (tidyverse)) {install.packages ("tidyverse")}
if (!require (DT)) {install.packages ("DT")}
library(tidyverse)
library(plotly)
library(scales)
library(DT)
dataset <- read_excel("Bivek_Data.xlsx")
Lets view the raw dataset what it looks like.
datatable(dataset, colnames = c('ID' = 1))
This is a sparse matrix and the table is in a wide format. We need to pivot it into a long format.
Let’s use Gather and summarize functions in R.
a <-dataset %>%
gather(key = Species, value, `Duttaphrynus melanostictus`: `Oligodon erythrogaster`)
b <- a %>%
mutate (SpeciesNo = ifelse(a$value > 0, 1, 0))
head(b)
## # A tibble: 6 x 4
## Ele Species value SpeciesNo
## <dbl> <chr> <dbl> <dbl>
## 1 1080 Duttaphrynus melanostictus 0 0
## 2 1064 Duttaphrynus melanostictus 0 0
## 3 1060 Duttaphrynus melanostictus 0 0
## 4 1080 Duttaphrynus melanostictus 0 0
## 5 1064 Duttaphrynus melanostictus 0 0
## 6 1060 Duttaphrynus melanostictus 0 0
c <- na_if(b, 0) %>%
drop_na()
head(c)
## # A tibble: 6 x 4
## Ele Species value SpeciesNo
## <dbl> <chr> <dbl> <dbl>
## 1 2003 Duttaphrynus melanostictus 1 1
## 2 1911 Duttaphrynus melanostictus 4 1
## 3 1811 Duttaphrynus melanostictus 2 1
## 4 1759 Duttaphrynus melanostictus 10 1
## 5 1646 Duttaphrynus melanostictus 1 1
## 6 1507 Duttaphrynus melanostictus 2 1
d <- c %>% group_by(Species) %>%
summarize (Max = max(Ele), Min = min(Ele))
Lets view the dataset after converting it into a long format.
datatable(d, colnames = c('ID' = 1))
Max/min column refers to the maximum/minimum elevation each species was found. Range of each species is the difference between its maximum and minimum elevation it was found.
ggplot(c, aes(Ele, Species, group = Species)) +
geom_line(size = 2) +
labs(x="Elevation", y=NULL, title=" Elevational ranges of herpetofaunal species")+
scale_x_continuous(breaks = seq(0, 3500, 100))+
theme_bw()
As it can be seen that there are few species that are found in only one elevation, but are not plotted in the map. We will increase their ranges by 10 meter elevation.
e <- d %>%
mutate (range = Max-Min) %>%
mutate ( MaxAdded = case_when
(range == 0 ~ (Max +10),
TRUE ~ Max))
head(e)
## # A tibble: 6 x 5
## Species Max Min range MaxAdded
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Amolops formosus 1745 1745 0 1755
## 2 Amolops marmoratus 1195 1195 0 1205
## 3 Asymblepharus sikimmensis 2425 1975 450 2425
## 4 Calotes versicolor 2019 2000 19 2019
## 5 Duttaphrynus himalayanus 2331 1947 384 2331
## 6 Duttaphrynus melanostictus 2254 1142 1112 2254
f <- e %>% select (Species, MaxAdded, Min) %>%
gather(MinMax, value, MaxAdded:Min)
head(f)
## # A tibble: 6 x 3
## Species MinMax value
## <chr> <chr> <dbl>
## 1 Amolops formosus MaxAdded 1755
## 2 Amolops marmoratus MaxAdded 1205
## 3 Asymblepharus sikimmensis MaxAdded 2425
## 4 Calotes versicolor MaxAdded 2019
## 5 Duttaphrynus himalayanus MaxAdded 2331
## 6 Duttaphrynus melanostictus MaxAdded 2254
p <- ggplot(f, aes(value, Species, group = Species)) +
geom_line(size = 1.5) +
labs(x="Elevation", y=NULL, title=" Elevational ranges of herpetofaunal species")+
scale_x_continuous(breaks = seq(0, 3500, 100))+
theme_bw()+
theme( axis.text.y = element_text(face = 'italic')) # To make species name italic
# View(f)
ggplotly(p)
You can hover your mouse cursor on the lower or upper end of the line of the graph to view lower or upper elevation of each herpetofaunal species.
Thanks,
Rajesh Sigdel
Bibilography