Installation

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)

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

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)
library(knitr)
opts_chunk$set(tidy = F, results = 'asis', comment = NA)

INDICATOR 1: 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)
indicator1 <- Atlas_i1_SpeciesByOcean_julien(df=df, yearAttributeName="year",
                                             oceanAttributeName="ocean",
                                             speciesAttributeName="species",
                                             valueAttributeName="value")

INDICATOR 1: D3JS rCharts result

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

INDICATOR 1: D3JS rCharts result

    plotRchartsNVD3bis <- nPlot(value ~ year, group = 'ocean', data = aggData, type = 'lineChart') 
    plotRchartsNVD3bis$print('chart_i1_d3js_bis')    

INDICATOR 1: ggplot result

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

INDICATOR 1: ggplot result

    plotRchartsRickshaw$print('chart_i1_Rickshaw')

INDICATOR 1: rCharts result example (see others)

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")

INDICATOR 2: ggplot result

print(indicator2) 

INDICATOR 2: rCharts result

require(rCharts)
aggData <-indicator2
plotRchartsHighcharts  <- hPlot(value ~ year, data = aggData, 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')

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

print(indicator3) 

INDICATOR 3: rCharts result


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) 

INDICATOR 6: netCDF / Thredds & WMS & Openlayers result


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) 

INDICATOR 9: 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)

test rCharts

require(rCharts)
haireye = as.data.frame(HairEyeColor)
n1 <- nPlot(Freq ~ Hair, 
  group = 'Eye',
  data = subset(haireye, Sex == 'Male'),
  type = 'multiBarChart'
)
n1$print('chart10')

Scatter Chart

p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
p1$xAxis(axisLabel = 'Weight')
p1


juldebar/IRDTunaAtlas documentation built on March 9, 2024, 3:40 a.m.