gpt4 book ai didi

r - 使用符号而不是线型来画线

转载 作者:行者123 更新时间:2023-12-01 13:55:13 25 4
gpt4 key购买 nike

我有七只猴子的饮食信息,用 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 调色板最多可以处理 6 个离散值,因为超过 6 个就很难区分

任何有关如何实现此目标的想法或其他清楚地区分个体(没有颜色)的想法都将不胜感激。

提前致谢

最佳答案

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

enter image description here

关于r - 使用符号而不是线型来画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26208132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com