[Returnanalytics-commits] r3616 - in pkg/FactorAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 16 17:15:01 CET 2015


Author: chenyian
Date: 2015-03-16 17:15:01 +0100 (Mon, 16 Mar 2015)
New Revision: 3616

Modified:
   pkg/FactorAnalytics/R/plot.tsfmUpDn.r
   pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd
Log:
Add legend and line color and line type option in plot.tsfmUpDn.r

Modified: pkg/FactorAnalytics/R/plot.tsfmUpDn.r
===================================================================
--- pkg/FactorAnalytics/R/plot.tsfmUpDn.r	2015-03-16 05:15:22 UTC (rev 3615)
+++ pkg/FactorAnalytics/R/plot.tsfmUpDn.r	2015-03-16 16:15:01 UTC (rev 3616)
@@ -14,6 +14,10 @@
 #' to provide the name of market returns. 
 #' @param assets.name The name of the asset used in \code{fitTsfmUpDn}. It supports one
 #' asset name at once.   
+#' @param line.color The color of fitted line. The default is \code{"blue"}.
+#' @param line.type The type of fitted line. The default is \code{"dotted"}.
+#' @param add.legend Alogic flag to add legend. The default is \code{TRUE}
+#' @param legend.loc The default is \code{"topleft"}.
 #' @param ... Other arguments can be used in \code{plot}. 
 #' @author Yi-An Chen
 #' 
@@ -34,7 +38,8 @@
 #' @export
 
 
-plot.tsfmUpDn <- function(object,mkt.name,assets.name,...) {
+plot.tsfmUpDn <- function(object,mkt.name,assets.name,line.color="blue",line.type="dotted",
+                          add.legend=TRUE,legend.loc="topleft",...) {
   
   if (is.null(mkt.name)){
     stop("Missing argument: mkt.name has to be specified for plot method.")
@@ -59,9 +64,13 @@
        main = paste("Actual vs Fitted values of the Asset ",assets.name,sep=""),
        xlab=mkt.name,ylab=assets.name,...)
   abline(v=0)
-  lines(coredata(plotDataUp$MktUp),coredata(plotDataUp$FittedUp),col="blue")
-  lines(coredata(plotDataDn$MktDn),coredata(plotDataDn$FittedDn),col="blue")
+  lines(coredata(plotDataUp$MktUp),coredata(plotDataUp$FittedUp),col=line.color,lty=line.type)
+  lines(coredata(plotDataDn$MktDn),coredata(plotDataDn$FittedDn),col=line.color,lty=line.type)
   abline(h=0)
+  if (add.legend){
+    legend(legend.loc,legend=c("Actual","Fitted"),pch=c(1,NA),lty=c(NA,line.type),
+           col=c("black",line.color),...)
+  }
  
   
 }
\ No newline at end of file

Modified: pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd
===================================================================
--- pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd	2015-03-16 05:15:22 UTC (rev 3615)
+++ pkg/FactorAnalytics/man/plot.tsfmUpDn.Rd	2015-03-16 16:15:01 UTC (rev 3616)
@@ -4,7 +4,8 @@
 \alias{plot.tsfmUpDn}
 \title{Plot actual against fitted values of up and down market time series factor model}
 \usage{
-\method{plot}{tsfmUpDn}(object, mkt.name, assets.name, ...)
+\method{plot}{tsfmUpDn}(object, mkt.name, assets.name, line.color = "blue",
+  line.type = "dotted", add.legend = TRUE, legend.loc = "topleft", ...)
 }
 \arguments{
 \item{object}{an object of class \code{tsfmUpDn} produced by \code{fitTsfmUpDn}.}
@@ -15,6 +16,14 @@
 \item{assets.name}{The name of the asset used in \code{fitTsfmUpDn}. It supports one
 asset name at once.}
 
+\item{line.color}{The color of fitted line. The default is \code{"blue"}.}
+
+\item{line.type}{The type of fitted line. The default is \code{"dotted"}.}
+
+\item{add.legend}{Alogic flag to add legend. The default is \code{TRUE}}
+
+\item{legend.loc}{The default is \code{"topleft"}.}
+
 \item{...}{Other arguments can be used in \code{plot}.}
 }
 \description{



More information about the Returnanalytics-commits mailing list