Paul Hiemstra skrev:
kerfuffle wrote:
hi folks,

this is driving me up the wall.  Apologies for posting twice in the same
week, I'm writing up a thesis.  I wish to color-code some dots in an xy
plot.  I've got a csv file with various elements, one of which is the
color-key (with the header 'color').  If the color-key is decimal (eg.
1,2,3) then I can use
plot (X ~ Y, col=data$color) The problem, however, is that using decimal numbers I can only produce 8 colors. It starts to recyle them after that (so, if possible values of my color column are 1,2,3,4,5,6,7,8,9,10,11, the values 1 and 9 both produce red, 2 and 10 produce black). However, I knew I could get more colors by using hexadecimal (tested with the legend) So, I carefully produced a csv file with hexadecimal values instead of decimal ones (eg. elements in the column are #ffffff, #ff0000) but if I use col=data$color it doesn't work, the entire plot is white. If I use these set of hexadecimal values in the legend, it works fine and I get lovely colors. I could use pch, but I'm already using symbols for another key. Grrr. What am I missing? Thanks!
Could you provide a small code sample that reproduces your problem (like stated in the posting guide)? And also include the info from sessionInfo().

cheers,
Paul

Hi

In addition to Paul's advice, you could try to convert the color column to character in the plot-call. The column is most likely stored as factor after the import of the csv-file. So maybe something like this would work:
with(data, plot(X ~ Y, col=as.character(color)))

If not, see Paul's advice.

Ivar

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to