Q:

How to give different colors to parts of the main of a plot

I simply represent the curves of Average Total Costs, Average Variable Costs, Average Fixed Costs and Marginal Costs.
plot(Q,ATCosts,ylab=NA,ylim=c(0,62),type="l")
par(new=T)
plot(Q,AVCosts,ylab=NA,ylim=c(0,62),type="l",col="blue")
par(new=T)
plot(Q,AFCosts,ylab=NA,ylim=c(0,62),type="l",col="red")
par(new=T)
plot(Q,MCosts,ylab=NA,ylim=c(0,62),type="l",col="green")

The main is: 
title(main="ATC,AVC,AFC,MC")

What I would like to know is if there is a way to give each piece of the main (containing a certain type of cost) the color related to that cost in the plot, in order to avoid to use a legend. Thus, ATC must be written in black; AVC must be written in blue...and so on.
I tried to overlap another title in the following way:
title(main="   ,AVC,   ,  ",col.main="blue")

But it didn't give a decent result.

A:

Not a general solution, because you have to play with the adj to get the right spacing, but it works:
plot(1)
mtext("ATC, ",col='black',line=2,adj=0.4)
mtext("AVC, ",col='blue',line=2,adj=0.45)
mtext("AFC, ",col='red',line=2,adj=0.5)
mtext("MC",col='green',line=2,adj=0.54)

