我的数据结构如下:
> Comparison
# A tibble: 12 x 3
round TotalShots Year
<int> <dbl> <dbl>
1 1 70 2021
2 2 68 2021
3 3 76 2021
4 4 73 2021
5 5 66 2021
6 6 70 2021
7 1 115 2020
8 2 106 2020
9 3 75 2020
10 4 73 2020
11 5 82 2020
12 6 84 2020我可以通过以下方式在ggplot2中绘制此图:
ggplot(Comparison, aes(x = round, y = TotalShots,
colour = factor(Year), label = TotalShots)) +
geom_line() +
geom_point(size = 14) +
geom_text(colour = "black", size = 5, check_overlap = TRUE) 但是,在图中,我将Rd3的标签打印为76,而不是75。我假设这是因为check_overlap = TRUE,但是这个图是错误的,因为year = 2020对于round =3应该有75的标签,而不是76。
有什么办法可以解决这个问题吗?

发布于 2021-06-08 11:31:25
您可以尝试使用ggrepel库,以使标签清晰,并避免重叠。
library(ggrepel)
library(ggplot2)
ggplot(Comparison, aes(x = round, y = TotalShots,
colour = factor(Year), label = TotalShots)) +
geom_line() +
geom_point(size = 14) +
geom_label_repel(colour = "black", size = 5, nudge_y = 0.8)

https://stackoverflow.com/questions/67880429
复制相似问题