Skip to content

Commit

Permalink
new text argument in plotFun.stn
Browse files Browse the repository at this point in the history
  • Loading branch information
cas committed Mar 19, 2019
1 parent 965e512 commit 5764542
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: plotFun
Type: Package
Title: Helper functions for plotting data
Version: 1.0.2
Date: 2019-01-15
Version: 1.0.3
Date: 2019-03-19
Author: A. Casanueva
Maintainer: A.Casanueva <ana.casanueva@meteoswiss.ch>
Description: Helper functions for plotting data.
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Changes in v1.0.3

Allow plotFun.stn to plot text on markers place.

* Changes in v1.0.2

Change function names to avoid S3 methods.
Expand Down
13 changes: 10 additions & 3 deletions R/plotFun.stn.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#' @param cex.unit numeric value giving the expansion factor of the units text. Default:1.
#' @param width.cbar numeric value giving the fraction of the plot (from 0 to 1) reserved for the colorbar. Modify this argument for a better appearance. Default=0.1
#' @param axis.lab display or not lon/lat ticks and labels. Default=FALSE
#' @param text display some text in each point. Length should be the same as lat and lon.
#' @param cex.cex numeric value giving the text expansion factor. Default: 1.
#' @param disp.warnings logical to set if warnings shoul be displayed.
#' @param export logical. If TRUE, the figure is exported as pdf file. Default: False.
#' @param export.path path (including file name) to save the plot.
Expand All @@ -47,7 +49,12 @@
#' unit.text = "degC")
#' }

plotFun.stn <- function(data, lon, lat, xlims, ylims, lattice=NULL, breaks= NULL, palette=rainbow(10), window.width=8, window.height=6, title.main=NULL, title.single=NULL, unit.text=NULL, mark.border=TRUE, cex.marker=1, cex.main=1, cex.single=1, cex.unit=1, cex.textcbar=1, width.cbar=0.1, disp.warnings=FALSE, axis.lab=FALSE, export=FALSE, export.format=NULL, export.path=NULL){
plotFun.stn <- function(data, lon, lat, xlims, ylims, lattice=NULL, breaks= NULL,
palette=rainbow(10), window.width=8, window.height=6, title.main=NULL,
title.single=NULL, unit.text=NULL, mark.border=TRUE, cex.marker=1,
cex.main=1, cex.single=1, cex.unit=1, cex.textcbar=1, width.cbar=0.1,
disp.warnings=FALSE, axis.lab=FALSE, export=FALSE, export.format=NULL,
export.path=NULL, text=NULL, cex.text=1){

# Verification checks
try(if(export & is.null(export.format)) stop("Cannot save plot: missing export.format"))
Expand All @@ -71,7 +78,7 @@ plotFun.stn <- function(data, lon, lat, xlims, ylims, lattice=NULL, breaks= NULL
if(is.null(breaks)) breaks <- set.Breaks(data)

# Plot
plotFun.stn1(data, lon, lat, xlims, ylims, breaks, palette, cex.marker, cex.main, title.main, axis.lab, mark.border=mark.border)
plotFun.stn1(data, lon, lat, xlims, ylims, breaks, palette, cex.marker, cex.main, title.main, axis.lab, mark.border=mark.border, text=text, cex.text=cex.text)

# Include colorbar
par(mar=c(3,0.6,3,5))
Expand Down Expand Up @@ -110,7 +117,7 @@ plotFun.stn <- function(data, lon, lat, xlims, ylims, lattice=NULL, breaks= NULL

# Plot subplots
for (i in 1:nrow(data)){
plotFun.stn1(data[i,], lon, lat, xlims, ylims, breaks, palette, cex.marker, cex.single, title.single[i], axis.lab, mark.border=mark.border)
plotFun.stn1(data[i,], lon, lat, xlims, ylims, breaks, palette, cex.marker, cex.single, title.single[i], axis.lab, mark.border=mark.border, text=text, cex.text=cex.text)
}

# Fill with empty plots when necessary (i.e. to fill the matrix)
Expand Down
12 changes: 10 additions & 2 deletions R/plotFun.stn1.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
#' @param cex.main numeric value giving the title expansion factor. Default: 1.
#' @param mark.border logical. If black contour for the cicles is plotted. Default=TRUE.
#' @param axis.lab display or not lon/lat ticks and labels. Default=FALSE
#' @param text display some text in each point. Length should be the same as lat and lon.
#' @param cex.cex numeric value giving the text expansion factor. Default: 1.
#'
#' @author Ana Casanueva (16.02.2017)
#'

plotFun.stn1 <- function(x, lon, lat, xlims, ylims, breaks= breaks, palette=palette, cex.marker, cex.main, title.main, axis.lab, mark.border=mark.border) {
plotFun.stn1 <- function(x, lon, lat, xlims, ylims, breaks= breaks, palette=palette, cex.marker,
cex.main, title.main, axis.lab, mark.border=mark.border,
text=NULL, cex.text=1) {

if(length(lon)== length(x) & length(lat)== length(x) & length(lon)== length(lat)){

Expand Down Expand Up @@ -48,7 +52,11 @@ plotFun.stn1 <- function(x, lon, lat, xlims, ylims, breaks= breaks, palette=pale
points(lon,lat, cex=cex.marker, pch=16, col=colcode)
}
#

if(!is.null(text)){
if(length(text)==length(lon)){
text(lon, lat, labels=text, cex=cex.text)
} else stop("Text length does not match the number of points.")
}
title(main= title.main, cex.main=cex.main, line=0)
} else stop("Number of stations does not match the data size")

Expand Down
6 changes: 5 additions & 1 deletion man/plotFun.stn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/plotFun.stn1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5764542

Please sign in to comment.