Dear sir, Thanks a lot for your great help. The graph is amazing. However, considering the number of classes (Here for an example purpose I have taken only 3 and in reality I will be dealing with even 25 classes), will it be possible (a) to generate separate graphs for each of these classes? (b) How do I draw a line connecting the plot points?
Kindly advise. Thanks again sir. Regards Akshata On Tue, Mar 8, 2011 at 7:16 PM, John Kane <jrkrid...@yahoo.ca> wrote: > I renamed your dataset to df1 (df is a reserved word and changed the column > names to make typing easier. > > Using gggplot2 does this give you something like what you want? > ================================================================= > library(ggplot2) > names(df1) <- c("class", "rate", "default") > > p <- ggplot(df1, aes(rate, default)) + geom_point() + facet_grid(class ~.) > p > ================================================================== > > > > --- On Tue, 3/8/11, Akshata Rao <akshata.rao1...@gmail.com> wrote: > > > From: Akshata Rao <akshata.rao1...@gmail.com> > > Subject: [R] How to plot multiple graphs? > > To: r-help@r-project.org > > Received: Tuesday, March 8, 2011, 7:40 AM > > 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]] > > > > ______________________________________________ > > R-help@r-project.org > > mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, > > reproducible code. > > > > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.