2014-10-05 3 views
3

나는 SE로 각각의 원숭이 식단에서 각 다이어트 항목의 비율을 자세히 설명한 7 마리의 원숭이의 다이어트 정보를 가지고 있습니다. 여기에 데이터가 포함됩니다.기호를 사용하여 회선 유형이 아닌 회선을 그립니다.

data <- structure(list(MonkeyID = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("P06", "P07", 
"P08", "P09", "P10", "P12", "P13"), class = "factor"), Diet = structure(c(3L, 
2L, 8L, 1L, 5L, 4L, 6L, 7L, 9L, 3L, 2L, 8L, 1L, 5L, 4L, 6L, 7L, 
9L, 3L, 2L, 8L, 1L, 5L, 4L, 6L, 7L, 9L, 3L, 2L, 8L, 1L, 5L, 4L, 
6L, 7L, 9L, 3L, 2L, 8L, 1L, 5L, 4L, 6L, 7L, 9L, 3L, 2L, 8L, 1L, 
5L, 4L, 6L, 7L, 9L, 3L, 2L, 8L, 1L, 5L, 4L, 6L, 7L, 9L), .Label = c("Apple", 
"Bird", "Cherry", "Goats", "Orange", "Porcupine", "Raccoon", 
"SmChildren", "SmMamm"), class = "factor"), ObsProp = c(0.333333333, 
0, 0, 0.033333333, 0.366666667, 0.166666667, 0.033333333, 0.066666667, 
0, 0, 0, 0, 0, 0.684931507, 0.315068493, 0, 0, 0, 0, 0, 0, 0.022727273, 
0.840909091, 0.113636364, 0, 0, 0.022727273, 0, 0, 0, 0.016666667, 
0.916666667, 0.066666667, 0, 0, 0, 0, 0.016129032, 0.032258065, 
0.080645161, 0.790322581, 0.064516129, 0, 0, 0.016129032, 0.083333333, 
0, 0, 0, 0.791666667, 0.125, 0, 0, 0, 0.105263158, 0, 0, 0, 0.657894737, 
0.210526316, 0, 0, 0.026315789), BootSD = c(0.086106917, 0, 0, 
0.032505407, 0.088036303, 0.067629445, 0.033002128, 0.046190006, 
0, 0, 0, 0, 0, 0.05399944, 0.05399944, 0, 0, 0, 0, 0, 0, 0.022101535, 
0.055554128, 0.04806202, 0, 0, 0.022399649, 0, 0, 0, 0.016603534, 
0.03591038, 0.032417222, 0, 0, 0, 0, 0.016058474, 0.022618108, 
0.034249235, 0.051625307, 0.03101898, 0, 0, 0.015862183, 0.055436816, 
0, 0, 0, 0.082385021, 0.067258445, 0, 0, 0, 0.049480715, 0, 0, 
0, 0.076734249, 0.066770967, 0, 0, 0.026230342)), .Names = c("MonkeyID", 
"Diet", "ObsProp", "BootSD"), class = "data.frame", row.names = c(NA, 
-63L)) 

이 코드

require(ggplot2) 
pd <- position_dodge(0.5) 
ColorBlind <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7") 
fig <- ggplot(data)+ 
    geom_point(aes(x=Diet, y=ObsProp ,color=MonkeyID),position = pd, size = 2.75)+ 
    geom_errorbar(aes(x=Diet, ymin=(ObsProp - BootSD), ymax=(ObsProp + BootSD),colour=MonkeyID), position = pd, cex =1.25)+ 
    ylab("Proportion of prey in diet")+ 
    theme(legend.position = "bottom")+ 
    theme_bw()+ 
    scale_colour_manual(values =ColorBlind)+ 
    scale_linetype_manual(values=c(1,2,3,4,5,6,7))+ 
    labs(color="Cougar ID") 
fig 

내가이 그림을 생성 할 수 있습니다이

> head(data) 
    MonkeyID  Diet ObsProp  BootSD 
1  P06  Cherry 0.33333333 0.08610692 
2  P06  Bird 0.00000000 0.00000000 
3  P06 SmChildren 0.00000000 0.00000000 
4  P06  Apple 0.03333333 0.03250541 
5  P06  Orange 0.36666667 0.08803630 
6  P06  Goats 0.16666667 0.06762944 

처럼 보인다.

fig

문제 : 컬러 그림은 비싸다. 색이없는 개별 원숭이를 구별해야합니다. 단순히 MonkeyIDlinetype에 매핑해도 식별 가능한 결과가 나오지 않습니다 (아래).

fig <- ggplot(data)+ 
    geom_point(aes(x=Diet, y=ObsProp ,type = MonkeyID),position = pd, size = 2.75)+ 
    geom_errorbar(aes(x=Diet, ymin=(ObsProp - BootSD), ymax=(ObsProp + BootSD),lty = MonkeyID), position = pd, cex =1.25)+ 
    ylab("Proportion of prey in diet")+ 
    xlab("Prey species")+ 
    ggtitle("Proportion of prey species in individual monkey diets")+ 
    theme(legend.position = "bottom")+ 
    theme_bw()+ 
    scale_colour_manual(values =ColorBlind)+ 
    scale_linetype_manual(values=c(1,2,3,4,5,6,7))+ 
    labs(color="Monkey ID") 
fig 

BWfig

질문 그것은 선을 '그리는'하는 기호를 사용할 수 있습니까? 예를 들어 개인을 더 잘 구분하는 선을 그리기 위해 열린 사각형 (또는 열린 원, 열린 삼각형, 닫힌 사각형 등)을 사용할 수 있습니까?

이 어떻게 보이는지 내가 (단지 염소에 대한)을 찾고의 양식에 일치시키는 및 단순화 된 버전 :

enter image description here

** 편집 : ** 나는 점의 모양에 덜 관심 각 개인을 묘사합니다. 더 중요한 것은 각 개인에 대해 geom_errorbar입니다. geom_errorbar이 각 개인에 고유하면 (위와 같음) 각 개인의 geom_point은 덜 중요하며 상호 침투를 완화하기 위해 제외 될 수도 있습니다. 또한 ggplot shape palette can deal with a maximum of 6 discrete values because more than 6 becomes difficult to discriminate

이 목표 또는 다른 아이디어를 분명히 구분할 수있는 다른 아이디어 (색상 없음)를 달성하는 방법에 대한 의견은 크게 감사하겠습니다.

미리 감사드립니다.

+2

(AES (X = 다이어트, Y = ObsProp 모양 = MonkeyID), ...) '? –

+0

포스트에서 편집/추가 된 내용보기 –

+1

당신이 원하는 것은 부당한 것은 아니지만 달성하기가 어렵다고 생각합니다 (특히'ggplot' 내). ggplot에서> 6 도형을 사용할 수 있습니다. 단지 scale_shape_manual()을 지정하면됩니다. 다행히도 다른 사람이 더 도움이 될 것입니다,하지만 나는 포인트 셰이프를 설정하는 것이 당신이 할 수있는 최선의 방법 일 것이라고 추측합니다. –

답변

2

Ben Bolker의 의견은 매우 유용했습니다. 실제로 원하는 결과를 변경하는 것이 최선의 선택이라고 생각합니다. 아래의 코드는 효과적으로 내 자신의 질문에 대한 답변으로 사용됩니다. 내 자신의 답변을 게시하는 것이 게시물을 폐쇄 된 것으로 표시하는 가장 좋은 방법이라고 생각합니다. 방법`geom_point 약

fig <- ggplot(data)+ 
     geom_point(aes(x=Diet, y=ObsProp ,shape = MonkeyID),position = pd, size = 3)+ 
     geom_errorbar(aes(x=Diet, ymin=(ObsProp - BootSD), ymax=(ObsProp + BootSD),lty = MonkeyID), position = pd)+ 
     ylab("Proportion of prey in diet")+ 
     xlab("Prey species")+ 
     ggtitle("Proportion of prey species in individual monkey diets")+ 
     theme(legend.position = "bottom")+ 
     theme_bw()+ 
     scale_linetype_manual(values=c(1,1,1,1,1,1,1))+ 
     scale_shape_manual(values =c(19,6,15,5,1,8,17))+ 
     labs(color="Monkey ID") 
    fig 

enter image description here

관련 문제