我有七只猴子的饮食信息,详细说明每只猴子饮食中每种饮食项目与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
我可以生成这个数字。
问题:颜色数字很贵。我需要区分没有颜色的单个猴子。简单地将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
问题是否可以使用符号“绘制”线条?例如,我可以使用空心方块(或空心圆,空心三角形,实心方块等)来描绘更能区分个体的线条吗?
我正在寻找的程式化和简化版本(仅适用于山羊)看起来像这样:
**编辑:**我对描绘每个人的点的形状不太感兴趣。更重要的是每个人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
对于如何实现这一目标或其他想法以明确区分个人(没有颜色)的任何想法将不胜感激。
提前致谢
答案 0 :(得分:2)
Ben Bolker的评论非常有帮助。实际上,我认为改变预期的结果是最好的选择。下面的代码有效地解决了我自己的问题。我想发布我自己的答案是将帖子显示为已关闭的最佳方式。
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