首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >线状图中点的不同形状

线状图中点的不同形状
EN

Stack Overflow用户
提问于 2022-07-10 20:43:04
回答 2查看 73关注 0票数 1

如何制作一个简单的线型图,其中每条线将有不同形状的附加点(geom_point)。这些点应与线条颜色相同。

代码语言:javascript
复制
my_data <- data.frame(
  TIME = c("T1-3","T3-5","T6-8","T8-10","T1-3","T3-5","T6-8","T8-10"),
  GROUP = c("A","A","A","A","B","B","B","B"),
  M = as.numeric(c("7.52","7.85","8.6","9.2","7.55","7.85","8.61","9.22")),
  SD = as.numeric(c("0.19","0.16","0.19","0.26","0.2","0.22","0.2","0.26")))

在下面的图表中,两条线上的点是相同的。

代码语言:javascript
复制
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP)) + 
  geom_line(position = position_dodge(0.3)) +
  geom_point(position = position_dodge(0.3)) +
  scale_shape_manual(values = c(0, 1)) +
  geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
  labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
  theme_light() +
  theme(legend.position = "top")

当我添加"shape = GROUP“美学时,就会创建两个传说,我需要一个传说:-)

代码语言:javascript
复制
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP, shape = GROUP)) + 
  geom_line(position = position_dodge(0.3)) +
  geom_point(position = position_dodge(0.3)) +
  scale_shape_manual(values = c(0, 1)) +
  geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
  labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
  theme_light() +
  theme(legend.position = "top")

我能在解决这个问题方面寻求帮助吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-10 22:12:48

我们可以使用guide_legend(override.aes = ...并将形状指南设置为none:

要获得填充的形状,只需更改形状0和1:

塑造15和16:

https://ggplot2.tidyverse.org/articles/ggplot2-specs.html

代码语言:javascript
复制
library(ggplot2)

ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP, shape = GROUP)) + 
  geom_line(position = position_dodge(0.3)) +
  geom_point(size = 3, position = position_dodge(0.3)) +
  scale_shape_manual(values = c(15, 16)) +
  geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
  labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
  theme_light() + 
  theme(legend.position = "top")+
  guides(colour = guide_legend(override.aes = list(linetype = c("solid", "solid")
                                                   , shape = c(15, 16))),
         shape = "none")

票数 3
EN

Stack Overflow用户

发布于 2022-07-10 21:12:55

我认为您可以将aes(shape = GROUP)放在geom_point中,并设置show.legend = F

代码语言:javascript
复制
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP)) + 
  geom_line(position = position_dodge(0.3)) +
  geom_point(aes(shape = GROUP), show.legend = F, position = position_dodge(0.3)) +
  scale_shape_manual(values = c(0, 1)) +
  geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
  labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
  theme_light() +
  theme(legend.position = "top")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72931761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档