The location may also be specified by setting 'x' to a singleSo, I ended up with something like this:
keyword from the list '"bottomright"', '"bottom"', '"bottomleft"',
'"left"', '"topleft"', '"top"', '"topright"', '"right"' and
'"center"'. This places the legend on the inside of the plot frame
at the given location.
R --vanilla --slave <<<"d=read.table('data1.csv', sep=',', header=F);e=read.table('data2.csv', header=F, sep=',');png('results.png');dh=hist(d\$V2, plot=F);eh=hist(e\$V2, plot=F);xlim=range(dh\$mids, eh\$mids);ylim=range(dh\$counts, eh\$counts);plot(dh, main='', xlab='value', col='orange', xlim=xlim, ylim=ylim);plot(eh, col='lightblue', add=T);legend('topright', legend=c('label1', 'label2'), fill=c('orange', 'lightblue'));q()"
Pre-calculating the range for the x and y axes (using the range operators) prevents you from cutting off data from one of the plots.
thanks! helped a lot :)
ReplyDeletelibrary(gplots) has a nice wrapper to legend called smartlegend, amongst other things.
ReplyDeletegreat! I'd never ever do without this!
ReplyDeletereally helpful! many thanks
ReplyDeleteGot me over the hump in seconds...thank!
ReplyDelete