1

I have made a rarefaction curves using the iNEXT package in R and added two horizontal lines for the asymptotes of both curves manually (the package does not do that, so I tried to utilize ggplot functions and it seemed to work), furthermore I extended the x/y axis. Unfortunately, my skills are apparently too limited to figure out how to add the asymptotes in the legend of the graph under, labelled as "Asymptotes: North and South" (or something like that). I would very much appreciate the help. I added my code below and the graph as a picture, if something is missing, let me know!

Best wishes and stay healthy!

### Rarefaction with iNEXT -> Species X Visits incidence_frequency data

# List for both regions
incidence_freq_north <- c(7,2,0,0,4,0,2,0,2,1,0,0,0,6,0,1,1,0,0,0)
incidence_freq_south <- c(23,0,0,1,9,2,0,4,1,1,1,2,6,1,4,1,0,8,2,7,1)

list_rarefaction_freq = list(North = incidence_freq_north, South = incidence_freq_south)

## create output file
out_freq <- iNEXT(list_rarefaction_freq, q=0, datatype="incidence_freq", endpoint=NULL,
             size=NULL, knots=400, se=TRUE, conf=0.95, nboot=400)

# Sample-size-based R/E curves, separating plots by "order"
ggiNEXT(out_freq, type=1, facet.var="order") +
  ylim(c(0,40)) + xlim(c(0,70)) + 
  theme_bw(base_size = 18) + 
  geom_hline(yintercept=24, linetype="solid", color = "darkslategray2") + 
  geom_hline(yintercept=10, linetype="solid", color = "coral1")

Graph as image

Ben
  • 13
  • 3

1 Answers1

1

I think one possible solution will be to draw your ggiNEXT graph on your own (here they provide a tutorial to do it: https://cran.r-project.org/web/packages/iNEXT/vignettes/Introduction.html)

Then, you can add a new dataframe corresponding to asymptope values and use new_color_scale function from ggnewscale package to add a new color scale on your graph:

df <- fortify(out_freq, type =1)

df.point <- df[which(df$method=="observed"),]
df.line <- df[which(df$method!="observed"),]
df.line$method <- factor(df.line$method, 
                         c("interpolated", "extrapolated"),
                         c("interpolation", "extrapolation"))

df.asympote <- data.frame(y = c(24,10),
                          Asymptote = c("North","South"))


library(ggnewscale)

ggplot(df, aes(x=x, y=y, colour=site)) + 
  geom_point(aes(shape=site), size=5, data=df.point) +
  geom_line(aes(linetype=method), lwd=1.5, data=df.line) +
  geom_ribbon(aes(ymin=y.lwr, ymax=y.upr,
                  fill=site, colour=NULL), alpha=0.2) +
  labs(x="Number of individuals", y="Species diversity") +
  scale_color_discrete(name = "Site")+
  scale_shape_discrete(name = "Site")+
  scale_fill_discrete(name = "Site")+
  scale_linetype_discrete(name = "Method")+
  theme_bw(base_size = 18)+
  new_scale_color()+
  geom_hline(data = df.asympote, aes(yintercept = y, color = Asymptote))

enter image description here

Does it answer your question ?

dc37
  • 15,840
  • 4
  • 15
  • 32
  • Oh my god yessss. This is way more elegant. Thanks a bunch, I'm going to mark this as the answer. :) – Ben Apr 09 '20 at 12:08
  • But, I realized now that "site" and "method" dont have a capital letter anymore and when I tried to edit that, I couldn't really find where. Would you mind helping me out there too? I want to change the label of the "site" -> "Region" and "method" -> "Method". Thanks! – Ben Apr 09 '20 at 12:42
  • Glad that my answer was what you were looking for ;0. To change the name of your category, the easiest way will be to rename column in`df`: `colnames(df)[3:4] <- c("Site","Method")` but I edited my answer to show you how to do it in `ggplot2`. Let me know if it is working for you. – dc37 Apr 09 '20 at 22:03
  • Amazing, I get it now! Thanks a bunch, this makes me very happy, you have improved my thesis ;) – Ben Apr 10 '20 at 07:37
  • Is it ok that if I have another small question with some detail, I ask you about here again? all the best! – Ben Apr 10 '20 at 07:45
  • Glad that it is working. If you have other questions, it's better to post new questions with details about your dataset and the desired output. Also do not forget to do some research on SO to be sure that your question does not have been answer before. – dc37 Apr 10 '20 at 17:02