2014-01-15 2 views
3

의 주석을 통해 그래프 ggplot2에서 기본 선을 채우거나 채우기 색을 사용하고 싶습니다. 어떻게해야할지 모르겠습니다. 아래의 코드에서 구체적으로, 녹색 4, 청색 4빨간색 4이 주석에 사용 된 것을 볼 수 있습니다. 이것들은 내 인데, 내 생각에 이 (가) 사용하고있는 것입니다.입니다.ggplot2의 기본 채우기 색을 사용하여 R

또한이 코드가 모범 사례를 따르지 않거나 다른 방법으로 이익을 얻을 수있는 경우 조언하십시오.

library(ggplot2) 
ggplot(data.frame(x = c(0, 1000)), aes(x)) + 
    stat_function(fun = dnorm, geom = "density", args = list(mean = 200, sd = 50), 
       aes(color="technology", fill="technology", alpha= 0.75)) + 
    stat_function(fun = dnorm, geom = "density", args = list(mean = 500, sd = 200), 
       aes(color="textiles", fill="textiles", alpha = 0.75)) + 
    stat_function(fun = dnorm, geom = "density", args = list(mean = 750, sd = 100), 
       aes(color="pharmaceuticals", fill="pharmaceuticals", alpha = 0.75)) + 
    labs(list(title="Fictious 'Density' Returns by Industry", x=NULL, y=NULL, color="Industry")) + 
    theme(legend.position="none") + 
    theme(axis.ticks = element_blank(), axis.text.y = element_blank()) + 
    annotate("text", label="technology", x=275, y=0.008, color="green4") + 
    annotate("text", label="textiles", x=500, y=0.0025, color="blue4") + 
    annotate("text", label="pharmaceuticals", x=835, y=0.0045, color="red4") 

답변

4

사용 ggplot_build 장면 뒤에 일어날 것을 볼 수 :

unique(sapply(ggplot_build(p)$data,'[[','colour')) 
    [,1]  [,2]  [,3]  
[1,] "#00BA38" "#619CFF" "#F8766D" 

unique(sapply(ggplot_build(p)$data,'[[','fill')) 
    [,1]  [,2]  [,3]  
[1,] "#00BA38" "#619CFF" "#F8766D" 
+0

감사합니다 - 나는 실제로 추가했다 또 다른'sapply (..., 독특한) '각각의 모든 (101 개) 요소를 잡는 피하기 위해 목록 레이블. – JasonAizkalns

관련 문제