[R] Multiple graphs
Jim Lemon
jim at bitwrit.com.au
Mon Mar 14 09:11:53 CET 2011
On 03/14/2011 06:22 PM, Akshata Rao wrote:
> ...
> However, there is only one small problem with the graphs. The graph doesn't
> give me the asset names. I.e. in the graph which is meant for bank doesn't
> show me the name bank. Under the X - label i.e. Rating, it gives me number
> 1, Similarly for corporate and sovereign it gives the numbers 2 and 3
> respectively.
>
Hi Akshata,
Try this:
DP_graphs <- function(Data = output, class.var="basel_asset_class_id",
class.labels=NULL,ratings="internal_scale_id",
IPD="default_probability") {
class <- unique(as.character(Data[[class.var]]))[1]
png(filename=sprintf("%s%s%s%s%s", "Curve ",
"( ", class," )",".png"),width=480,height=480)
par('bg'= "#FFFFCC")
par(xaxt="n")
# if the labels are not specified, default to the numbers
if(is.null(class.labels)) class.labels<-unique(class)
# stick your labels together here
class.labels<-paste("(",class.labels,")",sep="")
plot(as.numeric(factor(Data[[ratings]])), Data[[IPD]],
"b",ylab="PD", xlab="Rating",
fg="#804000", font.main=2,cex.main=1,col="Red",
col.main="black",col.axis="black" ,col.lab = "black")
# replace the class numbers with the appropriate labels
title("Exponential Curve", sub=class.labels[as.numeric(class)],
cex.main=1.2,font.main= 2, col.main= "black", cex.sub = 1,
font.sub = 2, col.sub ="black")
par(xaxt="s")
axis(1,at=1:length(unique(output$internal_scale_id)), labels =
internal_scale)
box(which="outer",bty = "o", col = "#804000")
dev.off()
}
d_ply(output, .(basel_asset_class_id), DP_graphs,
class.labels=c("bank","corporate","sovreign"))
Jim
More information about the R-help
mailing list