Hi Lu, Just store the id number as a variable at the top of your script, and modify the title() call as shown below.
score.id <- "003" ID <- c("001","001","002","002","002","003","003","003","004","004","005","005","006") test <- c("A","B","A","B","C","A","B","C","A","B","A","B","A") score <- c(60,90,32,56,89,45,77,82,68,79,56,77,90) mydata <- data.frame(ID,test,score) score_002 <- score[mydata$ID==score.id] lbls <- round(score_002/sum(score_002)*100) lbls <- paste(lbls,"%",sep="") par(mar=c(4,4,4,4),oma=c(0,0,0,0)) pie(score_002,labels=lbls,radius=0.5) title(main="Pie chart of score",font.main=3,cex.main=1,line=-2.6) title(main="(Total score: 177)",font.main=3,cex.main=0.8,line=-3.6) title(main=paste("ID is", score.id),font.main=3,cex.main=0.9,line=-22) -Ista On Wed, Feb 17, 2010 at 1:06 PM, Lu Wang <lueryy2...@yahoo.com> wrote: > Hi, > > I want to produce a pie chart with titles. I used the following code. So it > created a pie chart for the percentage of the score for ID="002". > > > ID <- > c("001","001","002","002","002","003","003","003","004","004","005","005","006") > test <- > c("A","B","A","B","C","A","B","C","A","B","A","B","A") > score <- c(60,90,32,56,89,45,77,82,68,79,56,77,90) > mydata <- data.frame(ID,test,score) > score_002 <- score[mydata$ID=="002"] > lbls <- round(score_002/sum(score_002)*100) > lbls <- paste(lbls,"%",sep="") > par(mar=c(4,4,4,4),oma=c(0,0,0,0)) > pie(score_002,labels=lbls,radius=0.5) > title(main="Pie chart of score",font.main=3,cex.main=1,line=-2.6) > title(main="(Total score: 177)",font.main=3,cex.main=0.8,line=-3.6) > title(main="ID is 002",font.main=3,cex.main=0.9,line=-22) > As you can see in the title:"(Total score: 177)" and "ID is 002" is inserted > by hand. If I want to change the ID to "003" and let R produce the > corresponding score sum and ID: 003. How can I do this? Is there any built-in > function or I need to write my own function? > > Thank you very much, > John > > > > [[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. > -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org ______________________________________________ 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.