【发布时间】:2020-09-09 02:21:48
【问题描述】:
我想绘制三个项目在三个月内的动物计数总和(“总和”),通过 geom_points 连接到 geom_paths。
我已通过手动排序“月份”因子的级别来指定 x 轴的顺序。
如何重新排序geom_path 以遵循 x 轴的新顺序并平滑连接点?
library(dplyr)
library(ggplot2)
df <- data.frame("Project" = c("Cass River", "Cass River", "Cass River", "Godley River", "Godley River", "Godley River", "Tasman River", "Tasman River", "Tasman River"),
"Month" = c("2019_Apr", "2019_Mar", "2019_May","2019_Mar", "2019_Apr", "2019_May", "2019_Mar", "2019_Apr", "2019_May"),
"Sum" = as.integer(c("66", "3", "42", "0", "23", "7", "18", "70", "12")))
#Set the order of the months
df <- df %>% mutate(Month = factor(Month, levels = c("2019_Mar", "2019_Apr", "2019_May")))
df %>%
ggplot(aes(x = Month, y = Sum, group = Project)) +
geom_point(aes(color = Project))+
geom_path(aes(color = Project))+
theme_classic() +
theme(axis.text.x = element_text(angle = 90)) +
xlab("\nDate") +
ylab("Total number of hedgehogs")
【问题讨论】:
-
我怀疑你想要
geom_line而不是geom_path。另外,考虑将df$Sum转换为整数/数字。 -
是的,已经完成了,谢谢!我将编辑问题,因为
df$Sum是我原始数据中的一个整数。