[R] Legend for two plots

Marc Giombetti giombetti at gmail.com
Fri Dec 18 18:03:39 CET 2009


Dear R users,

I am new to R and I couldn't figure out how to solve the following
problem:

I am trying to put a legend below two plots using the code below. The
legend appears in the second plot,
but I want the legend to appear below the two plots in the center of
the total chart. At the moment the
graphic looks like this: http://i48.tinypic.com/2h2fvhf.jpg

[code]
layout(matrix(1:2, nrow=1))
#c(down,left,top,right)
par(mar=c(4,4,3,1))
plot(totalExp , totalDiffs,
	main="Years of experience",
	cex.main = 0.9,
	cex.lab=0.8,
	xlab="Years of experience",
	ylab="COCOMO II - expert estimate",
	pch=totalPch,
	col = totalColors
)
abline(0,0)

plot(totalSoftwareEXP , totalDiffs,
	main="Years of prof. software experience",
	cex.main = 0.9,
	cex.lab=0.8,
	xlab="Years of experience",
	ylab="COCOMO II - expert estimate",
	pch=totalPch,
	col = totalColors
)
abline(0,0)

legend("topleft",  c("Security","Usability") ,col=c('red','blue'),
pch=c(8,9), cex=0.8,bg='#e0dcdc')
[/code]

Thanks a lot for your help! I really appreciate it!

Marc




More information about the R-help mailing list