2009-09-08 6 views

답변

9

체크 아웃 scale_brewer에 대한 ggplot 문서 http://www.had.co.nz/ggplot2/scale_brewer.html

몇 가지 예 : 여기

#see available pallets: 

library(RColorBrewer) 
display.brewer.all(5) 

#scatter plot 
dsamp <- diamonds[sample(nrow(diamonds), 1000), ] 
d <- qplot(carat, price, data=dsamp, colour=clarity) 
dev.new() 
d 
dev.new() 
d + scale_colour_brewer(palette="Set1") 
dev.new() 
d + scale_colour_brewer(palette="Blues") 
12

작은 데이터 세트입니다 :.

dat <- data.frame(x=1:20, 
        y=rnorm(20,0,10), 
        v=20:1) 

가한다고 가정 내 포인트 v 값을 사용하여 색 싶어 I scale_colour_gradient() 기능을 사용하여 채색이 수행되는 방식을 변경할 수 있습니다.

library(ggplot2) 
qplot(x,y,data=dat,colour=color,size=4) + 
    scale_colour_gradient(low="black", high="white") 

alt text http://i29.tinypic.com/amxtu0.png

이 예

그냥 당신이 시작할 수 있어야합니다. 자세한 내용은 다른 게시물에 언급 된 scale_brewer()을 확인하십시오.

8

데이터에 색상을 지정하려는 개별 범주가있는 경우 작업이 약간 더 쉽습니다. 예를 들어, 데이터 트랜잭션을 나타내는 각 행과 함께, 같이,

> d <- data.frame(customer = sample(letters[1:5], size = 20, replace = TRUE), 
>    sales = rnorm(20, 8000, 2000), 
>    profit = rnorm(20, 40, 15)) 
> head(d,6) 
customer sales profit 
     a 8414.617 15.33714 
     a 8759.878 61.54778 
     e 8737.289 56.85504 
     d 9516.348 24.60046 
     c 8693.642 67.23576 
     e 7291.325 26.12234 

하고 고객 색깔 거래의 산포도을하려는 경우, 당신은이

p <- ggplot(d, aes(sales,profit)) 
p + geom_point(aes(colour = customer)) 

을 수행 할 수 있습니다 얻으려면 ....

sales vs profit coloured on customer

관련 문제