Lemmens et al. (2015) did a detailed study of various biotic communities in artificial ponds in Belgium. They sampled 28 ponds that represented different types of management, a combination of fish farming strategies (no fish, farming young fish, low intensity management, no management), and drainage frequencies (> 10 years ago, occasional, annual). They also quantified taxon abundances for fish, zooplankton, and macro-invertebrates (different families and species within some groups) and covers of submerged, floating, and emergent vegetation. The macroinvertebrate dataset only included 23 ponds and we will use these data to illustrate CA by examining the ordination of the macroinvertebrate community (abundances of families).
The paper is here and the pond subset for this example is lemminvert2.csv
Lemmens, P., Mergeay, J., Van Wichelen, J., De Meester, L. & Declerck, S. A. (2015). The impact of conservation management on the community composition of multiple organism groups in eutrophic interconnected man-made ponds. PLoS One, 10, e0139371.
Plots used for QK use the ggplot classic theme, with some tweaks. Tweaks are consolidated into theme_QK; use this theme for figures and tweak the theme to avoid repetitive code changes.
source("../R/appearance.R")
packages: vegan
Convert data to contingency table
Get chi-square test of independence
lemminvert <- read_csv("../data/lemminvert2.csv")
Rows: 23 Columns: 32── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (2): site, manag
dbl (30): managsymb, ca, ba, ac, ly, pla, sp, vi, co, na, ne, no, ple, ga, as, ce, cha, chi, cu, cy, di, em, ep, li, ps, pt, sc, st, hi, le
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
lemminvert1.tab <- as.table(as.matrix(lemminvert[,-(1:3)]))
chisq.test(lemminvert1.tab,correct=F)
Warning: Chi-squared approximation may be incorrect
Pearson's Chi-squared test
data: lemminvert1.tab
X-squared = 24485.276, df = 616, p-value < 2.2204e-16
Very low P value
lemminvert1 <- lemminvert[,-(1:3)]
lemmens1.ca <- cca(lemminvert1)
summary(lemmens1.ca, scaling=1)
Call:
cca(X = lemminvert1)
Partitioning of scaled Chi-square:
Inertia Proportion
Total 1.306439 1
Unconstrained 1.306439 1
Eigenvalues, and their contribution to the scaled Chi-square
Importance of components:
CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 CA10 CA11 CA12 CA13 CA14
Eigenvalue 0.3646027 0.1563418 0.1471454 0.1350028 0.12477099 0.09851886 0.08073187 0.04604113 0.04071200 0.03138836 0.02620429 0.01864224 0.01378977 0.006884844
Proportion Explained 0.2790813 0.1196702 0.1126309 0.1033365 0.09550466 0.07541024 0.06179537 0.03524170 0.03116258 0.02402589 0.02005780 0.01426951 0.01055523 0.005269932
Cumulative Proportion 0.2790813 0.3987515 0.5113824 0.6147189 0.71022356 0.78563380 0.84742917 0.88267087 0.91383345 0.93785935 0.95791715 0.97218665 0.98274189 0.988011820
CA15 CA16 CA17 CA18 CA19 CA20 CA21 CA22
Eigenvalue 0.005143572 0.004453789 0.003260623 0.0011283312 0.0008856922 0.0005362529 0.0001551241 9.843940e-05
Proportion Explained 0.003937094 0.003409106 0.002495810 0.0008636694 0.0006779439 0.0004104692 0.0001187381 7.534941e-05
Cumulative Proportion 0.991948913 0.995358020 0.997853830 0.9987174993 0.9993954433 0.9998059125 0.9999246506 1.000000e+00
Scaling 1 for species and site scores
* Sites are scaled proportional to eigenvalues
* Species are unscaled: weighted dispersion equal on all dimensions
Species scores
CA1 CA2 CA3 CA4 CA5 CA6
ca 0.17013509 3.93120864 0.7873446 2.8609992 -0.15237208 -2.796024237
ba -0.68590692 -0.92415393 0.5568942 0.5929705 0.12571634 -0.824103302
ac -0.92980945 -0.83633688 2.4589545 7.3662448 4.91801734 4.054594983
ly -0.56642041 -0.48701985 -0.2655431 -0.3859842 -0.85068676 -1.183738353
pla -1.24803097 0.80303586 0.2682568 -1.2799896 -0.14655237 0.441236760
sp -1.61224042 0.49386288 0.5289079 0.5863945 1.03451278 1.537982543
vi 1.05822080 1.86992695 -3.4385351 3.5856090 -0.88871788 -0.186779833
co 0.04130891 0.33711854 -2.0715570 0.6390980 -0.13174480 0.410504053
na 0.63064839 3.76290951 1.4655338 3.9717044 0.01287423 -1.638271793
ne 2.85098180 8.59793333 3.4637891 4.1313131 -4.46912377 -3.423347292
no -0.36968252 3.84734637 2.6716572 7.0285838 1.92619062 -2.380971588
ple -1.84465012 0.35825842 1.6101553 2.5481032 2.84044097 3.284663824
ga 2.41981658 1.27718437 -2.0268421 -4.2481434 11.57053781 -4.903450593
as 0.68385458 4.55887807 -0.2074191 3.4730129 -0.30539328 -2.911485888
ce 0.63921989 0.03968881 0.8494813 -0.3517609 -0.80118353 -0.446429927
cha 1.55886263 -0.51771636 0.8257687 -0.5663022 0.32666594 2.487477251
chi 0.96328516 -0.59863320 0.2032072 -0.1519920 -0.18704299 -0.017213943
cu 1.13470087 0.29581964 0.1414151 -0.5743293 1.32025557 -0.114949369
cy 2.83092921 1.60264791 -2.5462389 -4.9555461 13.93842212 -6.232068735
di 1.87616642 1.71715599 0.8211940 -0.1888041 -0.19327579 0.300035020
em -0.87444250 3.20023337 1.6084198 -4.3190679 -0.80113483 0.936910444
ep 1.30710019 -0.27575937 -1.2739411 -1.7165683 -0.82446365 0.534217266
li 2.15386450 3.39960732 2.3782499 0.6009476 -1.23644967 -0.274164635
ps 1.30710019 -0.27575937 -1.2739411 -1.7165683 -0.82446365 0.534217266
pt 1.95392860 -0.32746807 -0.2541473 -0.8798595 -0.84411739 2.273883325
sc -1.31075104 3.89543192 2.1848920 -4.8395678 -0.79646907 1.017449080
st -0.48692684 2.88431170 -0.4254052 -1.5505721 0.34421889 -0.213297853
hi -0.38648868 1.28425854 0.2067127 -1.4413397 0.89683120 -0.007454139
le -0.17297453 6.09389055 1.5302564 1.0882310 -1.00937129 -3.302061164
Site scores (weighted averages of species scores)
CA1 CA2 CA3 CA4 CA5 CA6
sit1 0.23969055 0.04206140 -1.020184184 0.39192448 -0.088519730 0.17282105
sit2 0.71240762 -0.05119693 -0.037396608 -0.11878351 -0.105321366 0.22402039
sit3 0.99105670 -0.08508288 0.442331782 -0.19178710 -0.104321463 0.29945081
sit4 -0.47085442 0.43312594 -0.080908483 -0.35927362 -0.002534957 0.07913066
sit5 0.47657224 -0.04311270 -0.187454551 -0.23174155 -0.102869149 0.05263048
sit6 -0.02659785 -0.71628142 0.390171193 0.25278033 0.012257703 -0.47081710
sit7 -0.29312804 -0.20117665 -0.003254134 -0.08329747 -0.135956751 -0.20741608
sit8 -0.86110521 0.29396821 0.032450105 -0.11877704 0.127338239 0.27194167
sit9 0.65341519 -0.23441171 -0.087771656 -0.09401124 -0.020613418 0.40127092
sit10 -0.47790335 0.60901867 0.321496757 -0.65335525 -0.099376237 0.10023792
sit11 -0.54188046 -0.24089822 0.636167958 1.18087756 0.840920824 0.52015683
sit12 0.92507183 1.26019175 0.610239126 0.89472137 -0.739847891 -0.77293261
sit13 0.60305560 0.14621787 -0.369804301 0.29700577 -0.166801626 -0.05088771
sit14 0.63432671 -0.15775553 0.191600825 -0.03723570 -0.250904565 -0.22646761
sit15 -0.19917194 0.11858476 -0.835664293 0.17599339 -0.219887040 -0.04693498
sit16 0.41740442 2.11277456 0.495022850 1.48088915 -0.185520535 -1.24369574
sit17 1.31455936 1.73685090 0.797949667 0.41380482 -0.615411840 -0.22571775
sit18 0.38583015 0.29234766 -0.505964551 0.48406729 -0.110886212 -0.01840134
sit19 1.03216440 0.25056079 -0.374667292 -0.66901265 1.739110776 -0.61397631
sit20 0.61351444 0.43929335 0.391770379 0.29290927 -0.127158837 -0.23391512
sit21 1.19472453 -0.13404669 0.495357258 -0.21178099 -0.110793517 0.53375978
sit22 1.16414398 0.39629037 0.626816092 -0.08611117 -0.258055378 0.04211562
sit23 0.49366120 -0.13520930 0.039683974 0.01878772 -0.084600207 0.05591205
summary(lemmens1.ca, scaling=2)
Call:
cca(X = lemminvert1)
Partitioning of scaled Chi-square:
Inertia Proportion
Total 1.306439 1
Unconstrained 1.306439 1
Eigenvalues, and their contribution to the scaled Chi-square
Importance of components:
CA1 CA2 CA3 CA4 CA5 CA6 CA7 CA8 CA9 CA10 CA11 CA12 CA13 CA14
Eigenvalue 0.3646027 0.1563418 0.1471454 0.1350028 0.12477099 0.09851886 0.08073187 0.04604113 0.04071200 0.03138836 0.02620429 0.01864224 0.01378977 0.006884844
Proportion Explained 0.2790813 0.1196702 0.1126309 0.1033365 0.09550466 0.07541024 0.06179537 0.03524170 0.03116258 0.02402589 0.02005780 0.01426951 0.01055523 0.005269932
Cumulative Proportion 0.2790813 0.3987515 0.5113824 0.6147189 0.71022356 0.78563380 0.84742917 0.88267087 0.91383345 0.93785935 0.95791715 0.97218665 0.98274189 0.988011820
CA15 CA16 CA17 CA18 CA19 CA20 CA21 CA22
Eigenvalue 0.005143572 0.004453789 0.003260623 0.0011283312 0.0008856922 0.0005362529 0.0001551241 9.843940e-05
Proportion Explained 0.003937094 0.003409106 0.002495810 0.0008636694 0.0006779439 0.0004104692 0.0001187381 7.534941e-05
Cumulative Proportion 0.991948913 0.995358020 0.997853830 0.9987174993 0.9993954433 0.9998059125 0.9999246506 1.000000e+00
Scaling 2 for species and site scores
* Species are scaled proportional to eigenvalues
* Sites are unscaled: weighted dispersion equal on all dimensions
Species scores
CA1 CA2 CA3 CA4 CA5 CA6
ca 0.10273155 1.55440286 0.30202170 1.05120916 -0.053822295 -0.877608098
ba -0.41416664 -0.36541116 0.21362202 0.21787353 0.044406703 -0.258667190
ac -0.56144069 -0.33068823 0.94324346 2.70655932 1.737188205 1.272644688
ly -0.34201789 -0.19256801 -0.10186110 -0.14182114 -0.300487556 -0.371548412
pla -0.75359030 0.31752099 0.10290207 -0.47030312 -0.051766604 0.138494133
sp -0.97350848 0.19527375 0.20288662 0.21545734 0.365420305 0.482737566
vi 0.63897847 0.73937053 -1.31900601 1.31745058 -0.313921263 -0.058625920
co 0.02494329 0.13329692 -0.79463961 0.23482203 -0.046536134 0.128847839
na 0.38080025 1.48785726 0.56217192 1.45931256 0.004547555 -0.514216069
ne 1.72148950 3.39962932 1.32869335 1.51795715 -1.578625808 -1.074510466
no -0.22322296 1.52124366 1.02483523 2.58249347 0.680387116 -0.747332559
ple -1.11384289 0.14165565 0.61764806 0.93624266 1.003327197 1.030980896
ga 1.46114186 0.50499966 -0.77748718 -1.56088380 4.087053873 -1.539081061
as 0.41292739 1.80258382 -0.07956499 1.27607969 -0.107873880 -0.913848871
ce 0.38597592 0.01569299 0.32585705 -0.12924654 -0.283001560 -0.140124150
cha 0.94127772 -0.20470544 0.31676103 -0.20807488 0.115388006 0.780762252
chi 0.58165412 -0.23670002 0.07794933 -0.05584600 -0.066069077 -0.005403063
cu 0.68515893 0.11696731 0.05424617 -0.21102426 0.466353054 -0.036079980
cy 1.70938128 0.63368819 -0.97672536 -1.82080285 4.923460176 -1.956103928
di 1.13287317 0.67896477 0.31500618 -0.06937179 -0.068270688 0.094174135
em -0.52800884 1.26537469 0.61698232 -1.58694339 -0.282984359 0.294074773
ep 0.78925767 -0.10903546 -0.48867787 -0.63071404 -0.291224782 0.167678589
li 1.30055377 1.34420730 0.91228555 0.22080455 -0.436750346 -0.086054012
ps 0.78925767 -0.10903546 -0.48867787 -0.63071404 -0.291224782 0.167678589
pt 1.17982779 -0.12948112 -0.09748974 -0.32328441 -0.298167062 0.713720001
sc -0.79146214 1.54025672 0.83811436 -1.77818926 -0.281336274 0.319354010
st -0.29401782 1.14045902 -0.16318346 -0.56972250 0.121588223 -0.066949321
hi -0.23337091 0.50779680 0.07929402 -0.52958752 0.316787128 -0.002339684
le -0.10444607 2.40952892 0.58699923 0.39984577 -0.356539594 -1.036441523
Site scores (weighted averages of species scores)
CA1 CA2 CA3 CA4 CA5 CA6
sit1 0.39695472 0.1063766 -2.659532307 1.06667222 -0.250601268 0.55060095
sit2 1.17982779 -0.1294811 -0.097489736 -0.32328441 -0.298167062 0.71372000
sit3 1.64130226 -0.2151814 1.153120861 -0.52197294 -0.295336314 0.95403830
sit4 -0.77978830 1.0954100 -0.210921447 -0.97780876 -0.007176518 0.25210711
sit5 0.78925767 -0.1090355 -0.488677872 -0.63071404 -0.291224782 0.16767859
sit6 -0.04404906 -1.8115328 1.017142698 0.68797375 0.034701821 -1.50000441
sit7 -0.48545326 -0.5087918 -0.008483248 -0.22670464 -0.384896498 -0.66081933
sit8 -1.42608787 0.7434690 0.084594628 -0.32326678 0.360497306 0.86639528
sit9 1.08212963 -0.5928459 -0.228813148 -0.25586353 -0.058357032 1.27843308
sit10 -0.79146214 1.5402567 0.838114358 -1.77818926 -0.281336274 0.31935401
sit11 -0.89741547 -0.6092508 1.658435080 3.21390818 2.380665020 1.65719881
sit12 1.53202383 3.1871253 1.590840848 2.43509780 -2.094525363 -2.46253234
sit13 0.99872844 0.3697966 -0.964047966 0.80833890 -0.472219006 -0.16212620
sit14 1.05051695 -0.3989763 0.499486850 -0.10134169 -0.710316242 -0.72151673
sit15 -0.32985132 0.2999103 -2.178504842 0.47898834 -0.622504959 -0.14953296
sit16 0.69126905 5.3433751 1.290481939 4.03042783 -0.525212643 -3.96236480
sit17 2.17705934 4.3926343 2.080186061 1.12622235 -1.742244213 -0.71912771
sit18 0.63897847 0.7393705 -1.319006011 1.31745058 -0.313921263 -0.05862592
sit19 1.70938128 0.6336882 -0.976725363 -1.82080285 4.923460176 -1.95610393
sit20 1.01604947 1.1110079 1.021311639 0.79718975 -0.359989414 -0.74524421
sit21 1.97859928 -0.3390148 1.291353711 -0.57638886 -0.313658839 1.70053727
sit22 1.92795442 1.0022499 1.634055570 -0.23436249 -0.730560349 0.13417869
sit23 0.81755893 -0.3419551 0.103452702 0.05113316 -0.239505013 0.17813355
ordiplot(lemmens1.ca, scaling=1, type="text")
ordiplot(lemmens1.ca, scaling=2, type="text")
Get broken stick graphs
lemmens1.ca.eig <- lemmens1.ca$CA$eig
evplot(lemmens1.ca.eig)
screeplot(lemmens1.ca,bstick=TRUE)
Do nice biplots
library(ggrepel)
#extract scores into smaller file.show
a<-as.data.frame(lemmens1.ca$CA$u) #u is sites
b<-as.data.frame(lemmens1.ca$CA$v) #v is variables
b$fam<-row.names(b) #add family names for plotting
a<-cbind(lemminvert[c(1:3)],a) #Add site names & symbols from original data file
br=c("nm","li","nf","yf")
la=c("None", "Light", "No fish", "Young fish")
p1a<-ggplot(data=b, aes(x=CA1, y=CA2))+
geom_point()+
geom_text_repel(aes(label=fam), size=2, max.overlaps=25)+
theme_qk()+
xlim(-2,3)+
ylim(-2,10)
p2<-ggplot(data=a, aes(x=CA1, y=CA2, shape=manag, ) )+
geom_point()+
labs(y=NULL)+
scale_shape_manual(values=sym4,
name="Management",
breaks=br,
labels=la,
guide =
guide_legend(label.theme = element_text(size=6),
title=NULL)
)+
xlim(-2,3)+
ylim(-2,10)+
theme_qk()
p3<-p1a+p2
p3
Colour version of RH panel
p2a<-ggplot(data=a, aes(x=CA1, y=CA2, color=manag, ) )+
geom_point()+
labs(y=NULL)+
scale_color_viridis_d(
name="Management",
breaks=br,
labels=la,
guide =
guide_legend(label.theme = element_text(size=6),
title=NULL)
)+
xlim(-2,3)+
ylim(-2,10)+
theme_qk()
p3c<-p1a+p2a
p3c