Hi David:
I don't know if anyone corrected you on your use of bquote in the
title below,
but
plot(1,1)
title(main= bquote(ss~"is sum of ID = "~ID, .(ss, ID)) )
doesn't work - you get the text of ss and ID. You need
plot(1, 1)
title(main = bquote(.(ss)~"is the sum of ID = "~.(ID)))
instead. It's OK...I struggle with bquote, too :) Thanks for the
reminder about
substitute()...
Dennis
On Wed, Feb 17, 2010 at 11:03 AM, David Winsemius <dwinsem...@comcast.net
> wrote:
On Feb 17, 2010, at 1:30 PM, David Winsemius wrote:
On Feb 17, 2010, at 1:06 PM, Lu Wang 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?
?substitute
Or other options:
> ss <- 120
> ID = "003"
> plot(1,1)
> title(main= substitute(ss~"is sum of ID = "~ID, list(ss=ss,
ID=ID)) )
#Or the equivalent:
> plot(1,1)
> title(main= bquote(ss~"is sum of ID = "~ID, .(ss, ID)) )
#Or simply with paste:
> plot(1,1)
> title(main= paste(ss,"is sum of ID = ",ID))
The paste() method is what I would have tried a few months ago, but
I have been struggling to understand the proper use of expressions,
so I tried those first.
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
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.