plot_hydroMet {hydroToolkit}R Documentation

Methods to easily use ggplot2 or plotly (interactive)

Description

This method allows you to make plots (using simple and expressive arguments) of the variables contained inside an hydroMet_XXX object. The plot outputs can be static (ggplot2) or interactive (plotly).

Usage

plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "Date",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL,
  scatter = NULL
)

## S4 method for signature 'hydroMet_BDHI'
plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "Date",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL
)

## S4 method for signature 'hydroMet_CR2'
plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "Date",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL
)

## S4 method for signature 'hydroMet_DGI'
plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "Date",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL
)

## S4 method for signature 'hydroMet_IANIGLA'
plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "Date",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL
)

## S4 method for signature 'hydroMet_compact'
plot_hydroMet(
  obj,
  slot_name,
  col_number,
  interactive = FALSE,
  line_type = NULL,
  line_color = "dodgerblue",
  x_lab = "x",
  y_lab = "y",
  title_lab = NULL,
  legend_lab = NULL,
  double_yaxis = NULL,
  list_extra = NULL,
  from = NULL,
  to = NULL,
  scatter = NULL
)

Arguments

obj

a valid hydroMet_XXX object.

slot_name

string(s) with the name of the slot(s) to use in plotting.

col_number

numeric (vector) with the column's variable to plot. In case you decide to merge slots you must provide a list in which each element contains the column numbers of the variable to plot.

interactive

logical. Default value, FALSE, will return a ggplot2 class object. Otherwise you will get a plotly one.

line_type

string with line dash type (ggplot2) or mode in plotly case. ggplot2: 'solid' (default value), 'twodash', 'longdash', 'dotted', 'dotdash', 'dashed' or 'blank'. plotly: 'lines' (default value), 'lines+markers' or 'markers'.

line_color

string with a valid color. See 'colors()' or Rcolor document.

x_lab

string with x axis label.

y_lab

string with y axis label. In case you use double_yaxis argument you must supply both c('ylab', 'y2lab').

title_lab

string with the title of the plot. Default is a plot without title.

legend_lab

string with plot label(s) name(s). NOTE: ggplot2 double_yaxis does not support legend_lab in this package version, so giving values to this argument will be harmfulness.

double_yaxis

numeric vector with either 1 (= main axis - left) or 2 (= secondary axis - right) indicating whether the variable should be plotted in either left or right axis. NOTE: in this package version ggplot2 supports just one line plot for each 'y' axis.

list_extra

list with the ggplot2 argument to pass. This argument was design to allow the user to modify ggplot2 arguments (you can find nice examples in ggplot2 - Essentials) NOTE: in this package version this argument doesn't make sense for plotly (except for scatter plot in hydroMet_compact class).

from

string (or POSIXct - valid only in 'BDHI' and 'IANIGLA') with the starting Date. You can use 'from' without 'to'. In this case you will subset your data 'from' till the end.

to

string (or POSIXct - valid only in 'BDHI' and 'IANIGLA') with the ending Date. You can use 'to' without 'from'. In this case you will subset your data from the beginning till 'to'.

scatter

numeric vector of length two with the column number to plot as scatter. The first variable (column number) will be the 'x' variable and the second one the 'y' variable. This argument will work just for class hydroMet_compact.

Value

A ggplot2 or plotly objects to analyze your data.

Functions

Examples

# Path to file
dgi_path  <- system.file('extdata', package = "hydroToolkit")
file_name <- list.files(path = dgi_path, pattern = 'Toscas')

# Read Toscas
var_nom <- list(slotNames(x = 'hydroMet_DGI')[2:7])
names(var_nom) <- file_name

# Load Toscas meteo station data
toscas_dgi <- create_hydroMet(class_name = 'DGI')
toscas_dgi <- build_hydroMet(obj = toscas_dgi, slot_list = var_nom, path = dgi_path)

# Plot mean air temperature
plot_hydroMet(obj = toscas_dgi, col_number = 2, slot_name = 'tmean',
 legend_lab = 'Tmean(ºC)' )

# Now let's plot an interactive graph
plot_hydroMet(obj = toscas_dgi, col_number = 2, slot_name = 'tmean',
 interactive = TRUE, y_lab = 'Tmean(ºC)' ) 


[Package hydroToolkit version 0.1.0 Index]