我正在尝试创建一个图来显示每个组内计算值的平均值(按因素组织),以及单个点本身。我已经成功地做到了这一点,但是所有的点都使用相同的符号。我想为每个因素中的每个点使用不同的符号,并且最好为每个因素以相同的顺序使用相同的点。
我目前正在制作的图表类型的示例版本如下,但是同一列中的所有点都使用相同的符号。
我曾想过使用点的行号来定义符号形状,但我认为默认 ggplot2
中只有 25 种不同的形状可用。包,我的真实数据有超过 25 个点,而且我更喜欢在每列中使用相同的点,以保持图表看起来一致。
Mean_list <- data.frame(Cells = factor(c("Celltype1", "Celltype2", "Celltype3",
"Celltype4"),
levels =c("Celltype1", "Celltype2", "Celltype3", "Celltype4")),
Mean = c(mean(c(1, 2, 3)), mean(c(5, 8, 4)), mean(c(9, 8 ,3)),
mean(c(3, 6, 8, 5))))
values_list <- data.frame(Cells2 = rep(c("Celltype1", "Celltype2", "Celltype3",
"Celltype4"), times = c(length(c(1, 2, 3)),
length(c(5, 8, 4)), length(c(9, 8 ,3)),
length(c(3, 6, 8, 5)))),
values = c(1, 2, 3, 5, 8, 4, 9, 8, 3, 3, 6, 8, 5))
ggplot() + geom_col(data = Mean_list, aes(Cells, Mean, fill = Cells)) +
geom_point(data = values_list, aes(Cells2, values))
最佳答案
在绘图之前,我们可以为单元格中的每一行分配一个数字:
values_list <- values_list %>% group_by(Cells2) %>% mutate(shape = factor(seq_along(values)))
ggplot() +
geom_col(data = Mean_list, aes(Cells, Mean, fill = Cells)) +
geom_point(data = values_list, aes(Cells2, values, shape = shape))
关于r - 在 R ggplot2 中为同一因子内的每个点显示不同的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53705526/