2014-10-05 80 views
3

我有七隻猴子的飲食信息,詳細說明每隻猴子飲食中每種飲食項目與SE的比例。數據包括在這裏。使用符號繪製線條而不是線條類型

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)) 

,看起來像這樣

> 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 

有了這個代碼

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 

我可以生成這個數字。

fig

問題:彩色數字是昂貴的。我需要區分不帶顏色的單個猴子。簡單地將MonkeyID映射到linetype不會產生可辨別的結果(如下)。

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

怎麼樣'geom_point(AES(X =飲食,Y = ObsProp,形狀= MonkeyID),...)'? – 2014-10-05 23:50:36

+0

在帖子中看到編輯/添加的詳細信息 – 2014-10-06 00:10:47

+1

我認爲你想要什麼,雖然不是不合理,但實現起來會非常困難(尤其是在'ggplot'內)。可以在ggplot中使用> 6個形狀,您只需指定'scale_shape_manual()'。希望別人會更有幫助,但我猜測設置點形狀將會是你能做的最好的。 – 2014-10-06 00:18:37

回答

2

本博爾克的意見是非常有幫助的。事實上,我認爲改變期望的結果是最好的選擇。下面的代碼有效地解答了我自己的問題。我想發佈我自己的答案是將帖子顯示爲已關閉的最佳方式。

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