2016-09-02 2 views
3

ggplot에서 ggrepel의 포함을 형성.ggplot 색상 범례 모양이 전설에서 재미있는 모양에 이르게 숫자 믹스와

Q : 이것을 일반 모양으로 바꾸려면 어떻게해야합니까?

샘플 코드 :

data(mtcars) 
library(ggplot2) 
library(ggrepel) 

ggplot(mtcars, aes(x = mpg, y = wt, color = factor(vs), size = factor(cyl))) + 
    geom_point() + 
    geom_text_repel(aes(label = rownames(mtcars)), size = 5) 

sessionInfo :

R version 3.2.3 (2015-12-10) 
Platform: x86_64-pc-linux-gnu (64-bit) 
Running under: Ubuntu 16.04.1 LTS 

locale: 
    [1] LC_CTYPE=en_US.UTF-8  LC_NUMERIC=C    LC_TIME=nl_NL.UTF-8  LC_COLLATE=en_US.UTF-8  LC_MONETARY=nl_NL.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=nl_NL.UTF-8  
[8] LC_NAME=C     LC_ADDRESS=C    LC_TELEPHONE=C    LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C  

attached base packages: 
    [1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
    [1] magrittr_1.5  ggrepel_0.5  ggplot2_2.1.0.9000 

loaded via a namespace (and not attached): 
    [1] labeling_0.3  colorspace_1.2-6 scales_0.4.0  assertthat_0.1 plyr_1.8.4  rsconnect_0.4.3 tools_3.2.3  gtable_0.2.0  tibble_1.1  Rcpp_0.12.6  grid_3.2.3  digest_0.6.10 
[13] munsell_0.4.3 

답변

2

ggrepel는 show.legend 인수를 가지고, 그래서 우리는 show.legend = FALSE 다음과 같이해야합니다 :
논리적

show.legend합니다. 이 레이어가 범례에 포함되어야합니까? 기본 설정은 미학이 매핑 된 경우를 포함합니다. 거짓 절대 을 포함하고 TRUE는 항상 포함됩니다. 사이드 참고로

ggplot(mtcars, aes(x = mpg, y = wt, color = factor(vs), size = factor(cyl))) + 
    geom_point() + 
    geom_text_repel(aes(label = rownames(mtcars)), size = 5, show.legend = FALSE) 

, 명료 ggplot 외부 데이터를 준비 :

#fix the data 
plotDat <- mtcars 
plotDat$vs <- as.factor(plotDat$vs) 
plotDat$cyl <- as.numeric(as.factor(plotDat$cyl)) 
plotDat$myLabel <- rownames(plotDat) 

#then plot 
ggplot(plotDat, aes(x = mpg, y = wt, 
        color = vs, size = cyl, 
        label = myLabel)) + 
    geom_point() + 
    geom_text_repel(size = 5, show.legend = FALSE) 

enter image description here