The code for this function can be found here
The arguments to pass to the function are:
lower.vals
- Anumeric
vector or a column of amatrix
ordata.frame
upper.vals
- Anumeric
vector or a column of amatrix
ordata.frame
cols
- Acharacter
vector of length 2 corresponding to the colors for the upper and lower values respectivelybar.width
-numeric
value for width of the barsbar.spacing
-numeric
value for the amount of space between barsupper.y.text
- Acharacter
orexpression
to be plotted next to the upper valueslower.y.text
- Acharacter
orexpression
to be plotted next to the lower valuesy.lab.offset
-numeric
value for the y label offsety.lab.cex
-numeric
size of the y labelmargins
-numeric
vector for plotting margins
To demonstrate this function I will use data comparing the climatic conditions of invasive ranges of species to that of their native ranges (N. Crouch, unpublished data)
# The function
source("mirror.barplot.R")
# The data
dat <- read.csv("analysis_data.csv")
I will first calculate whether the temperature of the invasive ranges exceeds that of the native ranges
# Lower minimum temperature in invasive range
tMin <- dat$Native_Temp_Min - dat$Invasive_Temp_Min
tMin[tMin < 0] <- 0
dat$TempMinIncrease <- tMin
# Higher maximum temperature in invasive range
tMax <- dat$Invasive_Temp_Max - dat$Native_Temp_Max
tMax[tMax < 0] <- 0
dat$TempMaxIncrease <- tMax
Now the plot can be generated:
mirror.barplot(lower.vals = dat$TempMinIncrease, upper.vals = dat$TempMaxIncrease, upper.y.text = "Increase in Maximum Temperature", lower.y.text = "Increase in Minimum Temperature", cols=c("#0072B2", "#D55E00"), margins=c(0.05,0.75,0.05,0.1), y.lab.cex=0.6)
Each column in the plot represents a single species. The orange values below the line show where the minimum temperature in the invasive range exceeds that of the native range. The blue values show where the maximum temperature of the invasive range is greater than that of the native range.