[R] Colors and legend on a scatterplot?
buczkowski@delta.sggw.waw.pl
buczkowski at delta.sggw.waw.pl
Fri Jan 14 13:55:25 CET 2005
Hello
I am new to R and I cannot overcome the 2 problems
1.Defining my own color scale for a value on a scatterplot
2.Adding legend showing values for colours
I have a set of points in area of my research with coordinates X and Y and
a value which I would like to show with colors.
#values for points are residuals from regression
stepmod = step(wmodzad, direction="both")
#I am adding residuals to original data to get coordinates for residuals
expzad = cbind(zadrz, residuals(stepmod))
#I want to have colors for classes defined as standard deviation from mean
std = sd(residuals(stepmod))
mn = mean(residuals(stepmod))
sdclas = seq(-3*std+mn, 3*std+mn, by=std)
#I would like to have colors from green to red, but I can't do it so I am
doing only
palette( rainbow(6) )
#I am dividing residuals into earlier defined classes by
residsd = cut(residuals(stepmod), sdclas, labels=FALSE)
#or by (THEN POINTS DON'T APPEAR ON PLOT IN NEXT STEP)
residsd = cut(residuals(stepmod), sdclas)
# I am creating a plot
plot(expzad$X,zadrz$Y,col=residsd, pch=15 )
# I would like to add legend to plot showing values for colours from plot
but I can't do this. Simply help for 'legend' on my level of knowledge on
R is not helpfull.
loc = locator(1)
legend(loc$x, loc$y, legend = levels(residsd) )
Thanks in advance for your help
Rafal Buczkowski
More information about the R-help
mailing list