Setting up

Installation / Preliminaries

Preliminaries

To install R/qtl, you need to first install the package. (This needs to be done just once.)

You then load the R/qtl package using the library function Type (within R):

#git  clone https://github.com/juldebar/IndicatorsForFisheries.git
# setwd("/home/tomcat7/IndicatorsForFisheries/")
#devtools::build()
#install.packages("/home/tomcat7/IndicatorsForFisheries_0.2.tar.gz",type="source", repo=NULL)

install.packages("IndicatorsForFisheries")

#library(IndicatorsForFisheries)

Si besoin remettre les codes du serveur Github (dans un terminal dans le répertoire du package):

git fetch --all
git reset --hard origin/master

A noter qu'on peut faire des rapports paramétrés avec knitR: here


NVD3 Plots using rCharts

This is a short tutorial on how to use NVD3 with rCharts. The source for this tutorial can be found here

## require(knitr)
## require(rmarkdown)
## require(rCharts)
options(RCHART_WIDTH = 500, RCHART_HEIGHT = 300)
opts_chunk$set(results = 'asis', comment = NA, message = F, tidy = F)

Examples

INDICATOR 1: Time serie of catches according to oceans

WFS data access

Nombre total de représentations par le biais de cet indicateur: une série temporelle par espèce soit 13 indicateurs pour le moment cf indicateurs précalculés sur le serveur MDST

# require(IndicatorsForFisheries)
df <- readData(connectionType="remote", dataType="WFS",
       url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
       layer="ns11:i1i2_mv", 
       ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>',withSparql=FALSE)
indicator1 <- Atlas_i1_SpeciesByOcean_julien(df=df, yearAttributeName="year",
                          oceanAttributeName="ocean",
        speciesAttributeName="species",
                          valueAttributeName="value")
resultPlot <- ggplot(indicator1$data, aes(x=year, y=value, group=ocean)) + 
  geom_area(aes(fill=ocean), position="stack") + 
  geom_line(position="stack", color="grey20") + 
  scale_fill_manual(name="Ocean", values=indicator1$colors) +
  xlab("Year") + ylab("Catches in thousand tons") + 
  ggtitle(paste(indicator1$species, "catches by Ocean")) +
  theme(legend.position="bottom")

INDICATOR 1: D3JS rCharts result

    aggData <-indicator1
    plotRchartsNVD3 <- nPlot(value ~ year, group = 'ocean', data = indicator1$data, type = 'stackedAreaChart', id = 'chart')
    plotRchartsNVD3$xAxis(axisLabel = 'Year')
    plotRchartsNVD3$yAxis(axisLabel = 'Catches')
#     plotRchartsNVD3$chart(width = 500, height = 200, useInteractiveGuideline=TRUE)
    plotRchartsNVD3$print('chart_i1_d3js', include_assets = TRUE)  

INDICATOR 1: D3JS rCharts result

    plotRchartsNVD3bis <- nPlot(value ~ year, group = 'ocean', data = indicator1$data, type = 'lineChart') 
    plotRchartsNVD3bis$xAxis(axisLabel = 'Year')
    plotRchartsNVD3bis$yAxis(axisLabel = 'Catches')
    plotRchartsNVD3bis$print('chart_i1_d3js_bis', include_assets = TRUE)   

INDICATOR 1: ggplot result

External Web page here

    plotRchartsRickshaw <- Rickshaw$new()
    plotRchartsRickshaw$layer(value ~ year, data = indicator1$data, group='ocean', type = 'area', title = "C'est de la balle")
#     plotRchartsRickshaw$yAxis(orientation = 'right')
    plotRchartsRickshaw$set(width = 400, height = 200, legend = TRUE, slider = TRUE)  
    plotRchartsRickshaw$print('chart_i1_Rickshaw', include_assets = TRUE)  
plotRchartsRickshaw$save(".",standalone=TRUE)

INDICATOR 1: ggplot result

print(resultPlot)

ggplot_i1<-indicator1[2] print(ggplot_i1)
See other rCharts examples here


INDICATOR 2: WFS data access

## require(IndicatorsForFisheries)
df <- readData(connectionType="remote", dataType="WFS",
       url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
       layer="ns11:i1i2_mv", 
       ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>',withSparql=FALSE)
indicator2 <- Atlas_i2_SpeciesByGear_julien(df=df, 
                                 yearAttributeName="year", 
                                 gearTypeAttributeName="gear_type", 
                                 speciesAttributeName="species", 
                                 valueAttributeName="value")
    resultPlot <- ggplot(indicator2$data, aes(x=year, y=value, fill=gear_type, order=gear_type)) + 
    geom_bar(stat="identity", width=0.8) + 
    geom_bar(stat="identity", width=0.8, colour="grey20", show_guide=FALSE) + 
    scale_fill_manual(name="Gear type", values=indicator2$colors) +
    xlab("Year") + ylab("Catches in thousand tons") + 
    ggtitle(paste(indicator2$species, "catches by gear type")) +
    theme(legend.position="bottom")

INDICATOR 2: ggplot result

print(resultPlot)

INDICATOR 2: rCharts result

## require(rCharts)
aggData <-indicator2
plotRchartsHighcharts  <- hPlot(value ~ year, data = indicator2$data, type = 'column', group = 'gear_type', radius = 6, title = "Catches per month per fishing gear",width = "100%")
plotRchartsHighcharts$xAxis(labels = list(rotation = -45, align = 'right', style = list(fontSize = '13px', fontFamily = 'Verdana, sans-serif')), replace = F)
plotRchartsHighcharts$plotOptions(column = list(stacking = "normal", dataLabels = list(enabled = T, rotation = -90, align = 'right', color = '#FFFFFF', x = 4, y = 10, style = list(fontSize = '13px', fontFamily = 'Verdana, sans-serif'))))
plotRchartsHighcharts$legend(align = 'center', verticalAlign = 'top', y = 30, margin = 20)
plotRchartsHighcharts$chart(width = 800,height = 400, zoomType = "xy")
# plotRchartsHighcharts$chart(zoomType = "xy")
plotRchartsHighcharts$exporting(enabled = T)
plotRchartsHighcharts$print('chart_i2_Highcharts', include_assets = TRUE)  

INDICATOR 3: WFS data access

## require(IndicatorsForFisheries)
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2005</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>',
               layer="ns11:i3_mv")
#build the I3 indicator
indicator3 <- Atlas_i3_SpeciesYearByGearMonth_julien(df=df, 
                                 yearAttributeName="year", 
                                 monthAttributeName="month",
                                 gearTypeAttributeName="gear_type", 
                                 speciesAttributeName="species", 
                                 valueAttributeName="value",
                                 meanPrev5YearsAttributeName="mean_prev_5_years",
                                 stddevPrev5YearsAttributeName="stddev_prev_5_years")

INDICATOR 3: ggplot result

External Web page rCharts result

print(indicator3) 

INDICATOR 4: WFS data access

#library(IndicatorsForFisheries)
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i4_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2005</ogc:Literal></ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyIsGreaterThanOrEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsGreaterThanOrEqualTo></ogc:And></ogc:Filter>')


#build the I4 indicator
indicator4 <- Atlas_i4_SpeciesMonthByOcean_julien(df=df, 
                                          oceanAttributeName="ocean", 
                                          yearAttributeName="year", 
                                          monthAttributeName="month",
                                          speciesAttributeName="species", 
                                          valueAttributeName="value")

INDICATOR 4: ggplot result

print(indicator4) 

no rCharts version for now


INDICATOR 6: WFS data access

## require(IndicatorsForFisheries)
#fetch data from IRD WFS for indicator I6, with restriction on species="YFT" and year=2000
  df <- readData(connectionType="remote", dataType="WFS",
           url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i6i7i8_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>',withSparql=FALSE)

    #build the I6 indicator
    indicator6 <- Atlas_i6_SpeciesMap_julien(df=df, 
                              geomIdAttributeName="geom_id",
                              yearAttributeName="year", 
                              speciesAttributeName="species",                                         
                              valueAttributeName="value")

INDICATOR 6: ggplot result

print(indicator6) 

netCDF / Thredds & WMS & Openlayers result Exemple sur Thredds


INDICATOR 7: WFS data access

#library(IndicatorsForFisheries)
#fetch data from IRD WFS for indicator I7, with restriction on species="YFT" and year=2000
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i6i7i8_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>')

#build the I7 indicator
indicator7 <- Atlas_i7_SpeciesMapRelativeCatches(df=df, 
                              geomIdAttributeName="geom_id",
                              yearAttributeName="year", 
                              speciesAttributeName="species",                                         
                              valueAttributeName="value")

INDICATOR 7: ggplot result

print(indicator7) 

no rCharts version but Openlayers possible thourgh netCDF export and Thredds ncWMS


INDICATOR 8: WFS data access

#library(IndicatorsForFisheries)
#fetch data from IRD WFS for indicator I8, with restriction on species="YFT" and year=2000
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i6i7i8_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>')

#build the I8 indicator with targeted species = "YFT"
indicator8 <- Atlas_i8_SpeciesMapRelativeCatchesOtherSpecies(df=df, 
                                             targetedSpecies="YFT",
                                             geomIdAttributeName="geom_id",
                                             yearAttributeName="year", 
                                             speciesAttributeName="species",                                         
                                             valueAttributeName="value")

INDICATOR 8: ggplot result

print(indicator8) 

INDICATOR 9: WFS data access

## require(IndicatorsForFisheries)
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i9i10_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>')

#build the I9 indicator
indicator9 <- Atlas_i9_RelativeSizeFrequenciesBySchoolType_julien(df=df, 
                                                         yearAttributeName="year", 
                                                         speciesAttributeName="species", 
                                                         schoolAttributeName="school",
                                                         sizeClassLowerBoundAttributeName="class_low",
                                                         sizeClassUpperBoundAttributeName="class_up",
                                                         fishCountAttributeName="fish_count")

INDICATOR 9: ggplot result

print(indicator9) 

rCharts result


INDICATOR 10: WFS data access

#library(IndicatorsForFisheries)
#fetch data from IRD WFS for indicators I10, with restriction on species="YFT" and year >= 1980 and year <= 2005
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i9i10_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2005</ogc:Literal></ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyIsGreaterThanOrEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>1980</ogc:Literal></ogc:PropertyIsGreaterThanOrEqualTo></ogc:And></ogc:Filter>')

#build the I10 indicator
indicator10 <- Atlas_i10_RelativeSizeFrequenciesByDecade(df=df, 
                                                       temporalAgg=10,
                                                       yearAttributeName="year", 
                                                       speciesAttributeName="species", 
                                                       sizeClassLowerBoundAttributeName="class_low",
                                                       sizeClassUpperBoundAttributeName="class_up",
                                                       fishCountAttributeName="fish_count")

INDICATOR 10: ggpot result

print(indicator10) 

INDICATOR 11: WFS data access

#library(IndicatorsForFisheries)
#fetch data from IRD WFS for indicators I11 with restriction on species="YFT" and year=2000
df <- readData(connectionType="remote", dataType="WFS",
               url="http://mdst-macroes.ird.fr:8080/constellation/WS/wfs/tuna_atlas",
               layer="ns11:i6i7i8_mv", 
               ogcFilter='<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>species</ogc:PropertyName><ogc:Literal>YFT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>year</ogc:PropertyName><ogc:Literal>2000</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>')

#build the I11 indicator
indicator11 <- Atlas_i11_CatchesByCountry(df=df, 
                                     geomIdAttributeName="geom_id",
                                     countryAttributeName="country", 
                                     speciesAttributeName="species",                                         
                                     valueAttributeName="value")

INDICATOR 11: ggplot result

print(indicator11) 

NVD3 Plots using rCharts

This is a short tutorial on how to use NVD3 with rCharts. The source for this tutorial can be found here

#library(rCharts)
options(
  rcharts.mode = 'iframesrc', 
  rcharts.cdn = TRUE,
  RCHART_WIDTH = 700,
  RCHART_HEIGHT = 400
)
#library(knitr)
opts_chunk$set(tidy = F, results = 'asis', comment = NA)
#library(datasets)

Plotly

library(plotly)
p <- plot_ly(iris, x = Petal.Length, y = Petal.Width,
             color = Species, mode = "markers")
# print(p)
# p$print('plotly')
p


jsubei/IRDTunaAtlas documentation built on March 9, 2024, 3:05 a.m.