|
| 1 | +source('readInfo.R') |
| 2 | +if(!dir.exists('out'))dir.create('out') |
| 3 | + |
| 4 | +dadaRareN<-read.csv('work/dadaRareN.csv',row.names=1) |
| 5 | +dadaRareN<-structure(dadaRareN$rare,.Names=rownames(dadaRareN)) |
| 6 | +dadaRareN<-dadaRareN[goodIds] |
| 7 | +dadaWeights<-info[names(dadaRareN),'weight'] |
| 8 | +dadaSpecies<-sub('unknown_or_none $',' sp.',apply(info[names(dadaRareN),c('genus','species','subspecies')],1,paste,collapse=' ')) |
| 9 | +dadaClass<-info[names(dadaRareN),'class'] |
| 10 | +dadaSpecies[grepl('^unknown_or_none',dadaSpecies)]<-NA |
| 11 | +dadaCommon<-info[names(dadaRareN),'common'] |
| 12 | +dadaDat<-data.frame( |
| 13 | + 'weight'=log10(tapply(dadaWeights,dadaSpecies,mean)), |
| 14 | + 'otu'=log10(tapply(dadaRareN,dadaSpecies,mean)), |
| 15 | + 'class'=tapply(dadaClass,dadaSpecies,unique), |
| 16 | + 'common'=tapply(dadaCommon,dadaSpecies,unique), |
| 17 | + stringsAsFactors=FALSE |
| 18 | +) |
| 19 | +summary(lm(otu~weight,dadaDat)) |
| 20 | + |
| 21 | + |
| 22 | +library(ggrepel) |
| 23 | +library(scales) |
| 24 | +scientific_10 <- function(x) { |
| 25 | + parse(text=gsub("e", " %*% 10^", scales::scientific_format()(x))) |
| 26 | +} |
| 27 | +classColors<-structure( |
| 28 | + c('#8dd3c7','#ffed6f','#bc80bd','#fccde5','#80b1d3','#fdb462','#b3de69','#fb8072','#bebada','#ccebc5'), |
| 29 | + .Names = c("Actinopteri", "Aves", "Chondrichthyes", "Diplopoda", "Holothuroidea", "Insecta", "Malacostraca", "Mammalia", "Polychaeta", "Reptilia") |
| 30 | +) |
| 31 | +pdf('out/dadaSpeciesArea.pdf',width=7,height=7,useDingbats=FALSE) |
| 32 | +print( |
| 33 | + ggplot(dadaDat, aes(10^weight, 10^otu, label = sub(' ','\n',common))) + |
| 34 | + geom_smooth(method=lm, color='#00000033')+ |
| 35 | + geom_text_repel(size=2.5,box.padding=.12,point.padding=.3,lineheight=.7,min.segment.length=.1,max.iter=3e4,nudge_y=.02,nudge_x=.1,color='#00000099') + |
| 36 | + #scale_x_continuous(trans='log10',label=scientific_10)+ |
| 37 | + ylab('Number of sequence variants (rarefied to 500 reads)')+ |
| 38 | + xlab('Animal weight (g)')+ |
| 39 | + theme_classic(base_size = 16)+ |
| 40 | + scale_x_log10( |
| 41 | + breaks = scales::trans_breaks("log10", function(x) 10^x), |
| 42 | + labels = scales::trans_format("log10", scales::math_format(10^.x)) |
| 43 | + ) + |
| 44 | + scale_y_log10( |
| 45 | + breaks = scales::trans_breaks("log10", function(x) 10^x,n=3), |
| 46 | + labels = scales::trans_format("log10", scales::math_format(10^.x)) |
| 47 | + ) + |
| 48 | + annotation_logticks(sides = "lb",short = unit(1,"mm"), mid = unit(1,"mm"), long = unit(2,"mm"))+ |
| 49 | + geom_point(fill = classColors[dadaDat$class],pch=21,size=4) |
| 50 | +) |
| 51 | +dev.off() |
| 52 | + |
0 commit comments