[R] labeling in qplot
Nikos Alexandris
nikos.alexandris at felis.uni-freiburg.de
Wed Aug 5 09:37:44 CEST 2009
On Tue, 2009-08-04 at 20:16 -0700, Mohan S wrote:
> HI
>
> am plotting different density plots in one graph each with a different
> color.
>
> And i want to add labels to plot mentioning which color belongs to which
> data series.
>
> p2 <- qplot(corArms, data = data1, geom = "density", adjust=0.4, main="Arms
> Correlation All") +
> layer(data=data2, geom="density", adjust=0.4, color=I(2)) +
> layer(data=data3, geom="density", adjust=0.4, color=I(3));
>
> how can i add such a legend. Any pointers?
Hi Mo.
Perhaps smartlegend in gplots may be what you are looking for. The
example below might _not_ be close to what you demonstrate above - it's
just an example.
# install gplots if not installed
library(gplots)
# plot a density
plot(density(mod.b2.06, from=0, to=6000), main="Density plots for both
the pre- & postfire MODIS bands 2, 6 and 7", col="magenta", lty=2,
lwd=2)
# add another one
lines(density(mod.b2.07, from=0, to=6000), col="magenta4", lty=1, lwd=2)
# example of smartlegend
smartlegend(x="right", y="top", c("Prefire MODIS band 2", "Postfire
MODIS band 2"), col=c("magenta", "magenta4"), lty=2:1, lwd=2, cex=1.5)
Hope this helps.
Kindest regards, Nikos
More information about the R-help
mailing list