1) Using calendar dates as tick marks in graphs 2) combining two figures with calendar dates into one table

Hi everyone,

I'm getting lost in all the possibilities where I don't know why none of them works. I'm trying to put the calendar dates of my (sub)fossil samples as tick marks for the x axis in a table but can't seem to manage. The beetle data only has 18 samples but the pollen data around 80, is there also a possibility to not have to manually enter each of the calendar dates?

Secondly, at the end I was wondering if both graphs could be combined into one (provided that I can manually adjust the scales as the pollen has far more data points and goes further back in time than the beetles, and give the data points of beetles a different color).

Pollen <- tibble::tribble(
                                         ~V1,  ~V2,  ~V3,  ~V4,  ~V5,  ~V6,  ~V7,  ~V8,  ~V9, ~V10, ~V11, ~V12, ~V13, ~V14,
                               "Sample name", 2004, 1992, 1980, 1969, 1957, 1946, 1934, 1923, 1911, 1899, 1888, 1876, 1864,
                                     "Abies",    2,    0,    1,    2,    0,    3,    2,    9,    4,    6,    4,    2,    1,
                                      "Acer",    0,    0,    0,    2,    2,    0,    0,    0,    0,    0,    0,    0,    0,
                                     "Alnus",    7,   34,   22,    8,    7,    7,   18,   15,    6,    9,   15,    4,    8,
                             "Alnus viridis",    1,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    1,
                                    "Betula",   42,   68,   32,   14,   12,   22,   20,   21,   20,   15,   16,   14,   20,
                                  "Carpinus",    3,   10,    6,    1,    2,    0,    3,    3,    0,    3,    2,    1,    2,
                                   "Corylus",   14,   11,    4,    1,    1,    7,    5,   10,    4,    6,    3,    9,    7,
                                     "Fagus",   27,   14,   13,    2,    2,    6,    5,    6,   15,    4,    7,    8,   11,
                                  "Fraxinus",    0,    3,    3,    1,    2,    2,    1,    0,    0,    0,    0,    0,    0,
                                 "Juniperus",   55,    1,    0,    1,    2,    6,   12,    3,   12,   17,    9,   13,   13,
                                     "Larix",    1,    1,    1,    1,    0,    0,    3,    1,    1,    1,    1,    1,    1,
                                     "Picea",  114,  148,  107,  196,  209,  153,   77,   85,  110,  128,  188,  140,  222,
                                     "Pinus",  129,  226,  562,  257,  169,  167,  161,  168,  119,  105,  145,  114,  175,
                                   "Quercus",   29,    3,   18,    4,    3,    2,    6,    9,   11,   12,   17,    8,   16,
                                     "Salix",    3,    2,    5,    0,    3,    2,    3,    1,    1,    4,    0,    1,    0,
                                    "Sorbus",    1,    1,    1,    2,    2,    0,    0,    0,    1,    0,    0,    0,    1,
                                     "Tilia",    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
                                     "Ulmus",    0,    1,    0,    0,    0,    1,    0,    0,    0,    0,    0,    0,    1,
                                   "Populus",    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
                                   "Juglans",    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0
                             )
Beetles <- tibble::tribble(
                                ~SpeciesName,  2004,  1969,  1946,  1899,  1841,  1806,
                   "Cychrus caraboides (L.)",    0,    0,    0,    0,    0, 0.01,
              "Leistus terminatus (Hellwig)", 0.01,    0,    0,    0,    0,    0,
                               "Leistus sp.",    0, 0.01,    0,    0,    0,    0,
             "Notiophilus palustris (Duft.)",    0,    0,    0,    0, 0.02,    0,
               "Notiophilus biguttatus (F.)",    0,    0,    0, 0.02,    0,    0,
                  "Loricera pilicornis (F.)",    0,    0,    0,    0,    0, 0.01,
               "Dyschirius globosus (Hbst.)", 0.01,    0,    0,    0,    0,    0,
                "Trechus amplicollis Fairm.",    0, 0.01, 0.05, 0.02,    0,    0

#Library vegan
library(vegan)

Df_full <- Diera_Hollow_August_2019_beetle_data
row.names(Df_full)<-Df_full$SpeciesName 
Df_raw = subset(Df_full, select = -c(SpeciesName))

Df_pollen <- Pollen_Diera_hollow
row.names(Df_pollen)<- Df_pollen$SpeciesName
Df_pollen = subset(Df_pollen, select = -c(SpeciesName))

#Tried to name the columns of the beetle data but this had no effect on the later plotting:
names(Df_raw) <- c("2004","1969","1946","1899","1841","1806","1737","1693","1638","1593","1504","1388","1271","1136","1083","1030","978","926")

#Plotting of the Shannon diversity of untransposed raw counts data
plot(diversity(Df_raw, index = "shannon", MARGIN = 2, base = exp(1)), xlab="Sample number", ylab="Diversity-index")
title("Shannon diversity beetles")

plot(diversity(Df_pollen, index = "shannon", MARGIN = 2, base = exp(1)), xlab="Sample number", ylab="Diversity-index")
title("Shannon diversity pollen")

#So on both of the plots I would like to have the est. calendar dates AD of the samples(columns) displayed, rather than number 1:18. And as the pollen data has around 80 data points with calendar dates, it would be great if this can be done by selecting just a row and take all the data out of there.

#It would be great if this is possible. Then, I was also wondering if both figures (beetle and pollen diversity) could be combined into one figure where the 'beetle' data points are red and the 'pollen' data are black.

I have never used the vegan package. Looking at the documentation, the diversity() function returns a vector of indices or numbers of species. It seems that each column of Df_raw represents a year, so I would try using the list of years you assign as column names as the tick labels of a custom axis.

#Does this vector has more elements than there are columns in Df_raw? 
Yrs <- c("2004","1969","1946","1899","1841","1806","1737","1693","1638","1593","1504","1388","1271","1136","1083","1030","978","926") 
Idx <- diversity(Df_raw, index = "shannon", MARGIN = 2, base = exp(1))
plot(Idx, xaxt = "n", xlab="Sample number", ylab="Diversity-index")
axis(side = 1, labels = Yrs, at = 1:18)

Thank you for sharing this way of properly labeling the samples, the Yrs sghow up but only every other year, but I'm sure that would be able to solve. Is there a way to take all the dates from the first row, for 'Yrs'? The pollen data that I'm comparing the beetle data with has 70 samples so I'd rather not fill that in by hand. Something like Yrs <- c([1,]?

How do you select all values from the first row of a df, and can you turn that finally into labels?

If you have a data frame named DF, you can get its first row with

DF[1, ]

Here is an example of using the first row of a data frame to label an axis.

DF <- data.frame(A = 33:36, B = 44:47, C = 55:58)
DF
#>    A  B  C
#> 1 33 44 55
#> 2 34 45 56
#> 3 35 46 57
#> 4 36 47 58
DF2 <- data.frame(D = 11:13)
DF2
#>    D
#> 1 11
#> 2 12
#> 3 13
plot(DF2$D, xaxt = "n")
axis(side = 1, at = 1:3, labels = DF[1, ])

Created on 2019-09-29 by the reprex package (v0.2.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.