Learn R Programming

stacomiR (version 0.6.1)

report_annual-class: Class "report_annual"

Description

This class displays annual migration counts, for several counting device, taxa or stages.

Arguments

Slots

dc

Object of class ref_dc-class, the counting device, multiple values allowed

data

Object of class "data.frame" data for report lot

taxa

An object of class ref_taxa-class, multiple values allowed

stage

An object of class ref_stage-class, multiple values allowed

start_year

Object of class ref_year-class. ref_year allows to choose year of beginning

end_year

Object of class ref_year-class ref_year allows to choose last year of the report

Author

Cedric Briand cedric.briand@eptb-vilaine.fr

See Also

Other report Objects: report_dc-class, report_df-class, report_env-class, report_ge_weight-class, report_mig-class, report_mig_char-class, report_mig_env-class, report_mig_interannual-class, report_mig_mult-class, report_sample_char-class, report_sea_age-class, report_silver_eel-class, report_species-class

Examples

Run this code
# launching stacomi without database for demo
stacomi(database_expected=FALSE)
# the following piece of script will load the Arzal dataset and connected to iav postgres schema
# it requires a working database
# prompt for user and password but you can set appropriate options for host, port and dbname
if (FALSE) {
	stacomi(database_expected=TRUE, sch='iav')
	if (interactive()){
		if (!exists("user")){
			user <- readline(prompt="Enter user: ")
			password <- readline(prompt="Enter password: ")	
		}	
	}
	options(					
			stacomiR.dbname = "bd_contmig_nat",
			stacomiR.host ="localhost",
			stacomiR.port = "5432",
			stacomiR.user = user,
			stacomiR.user = password						
	)	
  r_ann<-new("report_annual")
  r_ann<-choice_c(r_ann,
	  dc=c(5,6,12),
	  taxa=c("Anguilla anguilla"),
	  stage=c("AGJ","AGG"),
	  start_year="1996",
	  end_year="2015",
	  silent=FALSE)
  r_ann<-connect(r_ann)	
}
# the following dataset has been generated by the previous code
data(r_ann)
xtr_ann<-stacomiR::xtable(r_ann,
	dc_name=c("Passe bassins","Piege anguille RG","Piege anguille RD"),
	tax_name="Anguille",
	std_name=c("Arg.","Jaun."))
# below not run but one can create a file as following
if (FALSE) {
  path=file.path(path.expand(get("datawd",envir=envir_stacomi)),
	  paste(paste(r_ann@dc@dc_selected,collapse="+"),"_",
		  paste(r_ann@taxa@taxa_selected,collapse="+"),"_",
		  paste(r_ann@stage@stage_selected,collapse="+"),"_",
		  r_ann@start_year@year_selected,":",
		  r_ann@end_year@year_selected,".html",sep=""),fsep ="/")
# here you can add an argument file=path
  print(xtr_ann,type="html")
  
# the following uses the "addtorow" argument which creates nice column headings,
# format.args creates a thousand separator
# again this will need to be saved in a file using the file argument
  print(xtr_ann,
	  add.to.row=get("addtorow",envir_stacomi),
	  include.rownames = TRUE,
	  include.colnames = FALSE,
	  format.args = list(big.mark = " ", decimal.mark = ",")
  )
# barplot transforms the data, further arguments can be passed as to barplot
  barplot(r_ann)
  barplot(r_ann,
	  args.legend=list(x="topleft",bty = "n"),
	  col=c("#CA003E","#1A9266","#E10168","#005327","#FF9194"))
  
# An example with custom arguments for legend.text (overriding plot defauts)
  data(r_ann_adour)
  if (requireNamespace("RColorBrewer", quietly = TRUE)){
	lesdc<-r_ann_adour@dc@data$dc_code[r_ann_adour@dc@data$dc%in%r_ann_adour@dc@dc_selected]
    barplot(r_ann_adour,
		legend.text=lesdc,
		args.legend=list(x="topleft",bty = "n"),
		col=RColorBrewer::brewer.pal(9,"Spectral"),
		beside=TRUE)
  }
  plot(r_ann_adour)
}

Run the code above in your browser using DataLab