合并两个稳定同位素图:标准椭圆误差(锡拉尔)和均值/标准差(Simmr)

时间:2019-03-15 17:13:33

标签: r ggplot2 dplyr

我想结合两个稳定的同位素分析图:一个具有标准椭圆误差(按siar表示),另一个具有均值和标准偏差(以simmr表示)。最好用ggplot做到这一点。 那就是我到目前为止所得到的: 标准椭圆误差: DataFrame->解剖https://www.dropbox.com/s/240z8mz9qzozb5f/Anatomy1.csv?dl=0

Anatomy<-Anatomy[!(is.na(Anatomy$d_15N.14N) | Anatomy$d_15N.14N==""), ] ##### Delete all empty rows ###
Anatomy<-Anatomy[!(is.na(Anatomy$d_13C.12C) | Anatomy$d_13C.12C==""), ]


#first you need to subset your data manually by each species (or whatever group you're using)

A.p. <- subset(Anatomy, Anatomy$Species =="A._polymorpha", use = "complete.obs")
P.ae. <- subset(Anatomy, Anatomy$Species =="P._aequipapillae", use = "complete.obs")
P.c. <- subset(Anatomy, Anatomy$Species =="P._charcoti", use = "complete.obs")
P.t. <- subset(Anatomy, Anatomy$Species =="P._turqueti", use = "complete.obs")



#next calculate standard.ellipse for each subset

SE1 <- standard.ellipse(A.p.$d_13C.12C, A.p.$d_15N.14N)
SE2 <- standard.ellipse(P.ae.$d_13C.12C, P.ae.$d_15N.14N)
SE3 <- standard.ellipse(P.c.$d_13C.12C, P.c.$d_15N.14N)
SE4 <- standard.ellipse(P.t.$d_13C.12C, P.t.$d_15N.14N)

#create name variable for each group (so ggplot2 knows how to colour it)

#the name needs to be the same as your original data frame that contains your isotopic data

A.p._ <- rep("A._polymorpha", length(SE1$xSEAc))
P.ae._ <- rep("P._aequipapillae", length(SE2$xSEAc))
P.c._ <- rep("P._charcoti", length(SE3$xSEAc))
P.t._ <- rep("P._turqueti", length(SE4$xSEAc))


#create new data frame with your names and ellipse outputs

species <- c(A.p._,P.ae._,P.c._,P.t._)
x <- c(SE1$xSEAc,SE2$xSEAc,SE3$xSEAc,SE4$xSEAc)
y <- c(SE1$ySEAc,SE2$ySEAc,SE3$ySEAc,SE4$ySEAc)

       df_SE <- data.frame(x,y,species)

       plot(df_SE$x, df_SE$y)

       #When you plot SE1$xSEAc vs SE1$ySEAc you should see the ellipse(s) form as a series of points

       #This gives you your SEAc (sample size corrected area)

       #If you also want hull total area (TA), implement the next bit too

       #I got the find_hull function from the stack overflow page linked below


       find_hull <- function(df_SE) Anatomy[chull(df_SE$x, df_SE$y), ]
       hulls <- ddply(df_SE, "species", find_hull)

       #Plot your data. Example below, customise as necessary

       plot <- ggplot(Anatomy, aes(x=d_13C.12C, y=d_15N.14N, color=Species)) +
         #scale_shape_manual(values = c(3:7)) +
         theme_bw() +
         theme(legend.text = element_text(face = "italic")) +
         scale_fill_discrete(labels = c(expression(italic("A. polymorpha"), italic("P. aequipapillae"), italic("P. charcoti"), italic("P. turqueti")))) +
         geom_point(size=2) +
         ylab(expression(paste(delta^{15}, "N (\u2030)"))) +
         xlab(expression(paste(delta^{13}, "C (\u2030)"))) +
         ggtitle("Stable Isotope Signatures & standard elipse error")+
         geom_path(data=df_SE, aes(x=x, y=y, color=species), linetype=1, size=1)

Standard elipse error

对于均值和标准差,我使用了这个:

df<-Anatomy %>%
  select(Species,d_13C.12C, d_15N.14N)
df<-df %>% drop_na()

df<-df %>%
  group_by(Species)%>%
  arrange(Species)

s_means<- df %>%
  group_by(Species) %>%
  summarise_each(funs(mean),d_13C.12C,d_15N.14N)

s_sds <- df %>%
  group_by(Species) %>%
  summarise_each(funs(sd), d_13C.12C,d_15N.14N)

s_means[1] = NULL
s_sds[1] = NULL
colnames(df)=NULL

s_names<-c("A. polymorpha","P. aequipapillae","P. charcoti","P. turqueti")
mix<-matrix(c(-25,9), nrow = 1, ncol = 2)

simmr_in = simmr_load(mixtures=mix,
                      source_names=s_names,
                      source_means=s_means,
                      source_sds=s_sds
                      )
plot(simmr_in)

Standard deviation and mean

0 个答案:

没有答案