[R] 2d plotting and colours

TEMPL Matthias Matthias.Templ at statistik.gv.at
Wed Mar 30 08:45:54 CEST 2005


Hi!

There are more than 8 colors.

x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
                matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
     
(cl <- kmeans(x, i, 20))
    
s <- c("tomato4", "turquoise", "slateblue", "wheat", "snow", "skyblue",
"peru", "pink")
# see at:    
colors()
     
plot(x, col = s)
     
points(cl$centers, col = s, pch = 8, cex=2)


Best,
Matthias




> Hi!
> 
> I am new to R just 3 days in it and i apologize if my 
> questions seem very 
> trivial and consumed your valuable time.
> 
> I am coding in perl and i stumbled upon R regarding plotting good 
> statistical graphs.
> 
> I tried the kmean clustering for a large matrix ,say > 150 * 
> 150 . I tried 
> the example code given in the tutorial to perform 2d plot
> 
> # i ranges from 2 to 10
> cl <- kmeans(x, i, 20)
> plot(x, col = cl$cluster)
> points(cl$centers, col = 1:i )
> 
> I see that there are only 8 colours defined , namely 
> black,red,green,blue,cyan,magenta,yello,gray.
> 
> How should i set my colour preferences to obtain my palette 
> of colours? I  
> checked in the totorial which talks about R.colors and 
> palatte , but i 
> failed to understand how to set it.
> 
> Thank You
> 
> Asha
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read 
> the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list