[R] Change legend in the 'hydrogeo' package

Tomas Lanczos lanczos at fns.uniba.sk
Tue Jul 8 13:07:57 CEST 2008


At first sorry for the possibly dumb question of a newbie.

I am using the hydrogeo package to visualize approx. 300 data within the 
Piper-Hill diagrams. The package is using a dataframe with 6 columns, 
first of them is containing the row.names, next four with the data 
itself. The last column contains "WaterTypes" dividing data to several 
categories. The diagram is created by the piper function, assigning 
different symbols following the row.names (I don't need id, however I 
can assign one symbol for the whole dataset using pch ) and assigmning 
colours following WaterTypes. Untill now it's working very well, what I 
need however is to change the legend, as it is showing all the 300 rows, 
even I assigned only one symbol. For me it is more appropriate to show 
the categories from the "WaterTypes" columns assigned to the colours.

Could somebody give me a hint how to change the code to give me an 
appropriate result? The answer is probably in the help assigned to the 
"legend" of the graphics package, but it's quite unclear to me.

Many thanks in advance

Tomas

The piece of code from the hydrogeo package creating the legend is here:

  ylegend <- X
     plotlegend <- function(dd, X, ...) {
         xid <- c(X + p)
         yid <- c(ylegend - (X/30) * 1:nrow(dd))
         text(xid, yid, labels = row.names(dd), vfont = c("serif",
             "plain"), cex = 0.7)
         if (is.character(dd$pch)) {
             text(xid - (X/15), yid, labels = c(1:nrow(dd)), vfont = 
c("serif",
                 "plain"), cex = 0.7)
         }
         else {
             points(rep(xid - (X/15), length(yid)), yid, pch = dd$pch,
                 col = dd$col)
         }
         return(min(yid))
     }



More information about the R-help mailing list