Dear R helpers,

I have following data.frame giving asset class (i.e. bank, corporate,
sovereign etc. as there could be number of classes) and rating-wise default
frequency.

I need to plot graphs for each of these classes i.e. bank, corporate and
sovereign where I will be plotting ratings (AAA, AA, etc) on the x-axis and
their respective default probabilities on Y-axis.

I have tried to write a function as given below, but it produces only one
graph and that too just a straight line. I have recently started my R
venture and trying to learn through the help I receive from various R forum
helpers and through old R mails which are achieved.

My code is as given below.

library(plyr)

df = data.frame(basel_asset_class =
c("bank","bank","bank","bank","bank","bank","bank","corporate","corporate","corporate","corporate","corporate","corporate","corporate","sovereign","sovereign","sovereign","sovereign","sovereign","sovereign","sovereign"),
ratings =
c("AAA","AA","A","BBB","BB","B","CCC","AAA","AA","A","BBB","BB","B","CCC","AAA","AA","A","BBB","BB","B","CCC"),
default_probability =
c(0.0027,0.0029,0.0031,0.0034,0.0037,0.004,0.0043,0.0025,0.0024,0.0024,0.0023,0.0022,0.0021,0.0021,0.003,0.0031,0.0032,0.0033,0.0034,0.0035,0.0036))

n_name = as.character(unique(df$basel_asset_class))

IPD = df$default_probability

internal_category = c(1:7)      # Total types of ratings

DP_yearly_graphs = function(class, ratings, IPD)

{
    flname = paste("Exponential Curve For " , n_name)
    png(filename=sprintf("%s%s%s%s%s", "Curve ", "( ", n_name," )",
".png"),width=480,height=480)

    par('bg'= "#FFFFCC")
    par(xaxt="n")

    plot(internal_category, 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")
    title("Exponential Curve", sub = paste("(", n_name,")"), 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:7)
    box(which="outer",bty = "o", col = "#804000")
    dev.off()

}

output_graph <- ddply(.data=ons1, .variables = "basel_asset_class",
.fun=function(x) DP_yearly_graphs(class = x$n_name,
ratings=x$ratings, IPD = x$IPD))

Don't understand where I am going wrong. Will be too grateful if someone can
guide me through.

Thanking in advance.

Regards

Akshata

	[[alternative HTML version deleted]]

