我在控制geom_points和geom_text的颜色方面遇到了一些麻烦。我希望我的观点是'团队'的颜色(这是我在scale_colour_manual中使用我指定的颜色)然后我想根据'团队'为我的文字着色...所以一个标签是白色的其他黑色。
我已经搜索了一个解决方案,但似乎无法做到正确 - 任何提示或答案都将不胜感激。
library(gganimate)
library(ggplot2)
DB_2 <- read.csv("Player Test.csv")
DataX <- DB_2[ which(DB_2$Time_UpD > 700 & DB_2$Time_UpD < 750 & DB_2$Player != 'P.Joao'), ]
p <- ggplot(DataX, aes(x=DataX$X_Location, y=DataX$Y_Location, frame = DataX$Time_Up, color=DataX$Team)) +
theme(panel.background = element_rect(fill = "#359935", ), legend.position="none", panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(),axis.title.x=element_blank(),axis.title.y=element_blank()) +
# **** Start of Pitch
# Top Half
geom_rect(xmin = -330, xmax = 330, ymin = 0, ymax = 515, color = "white", alpha=0, size=0.1) +
# Bottom Half
geom_rect(xmin = -330, xmax = 330, ymin = -515, ymax = 0, color = "white", alpha=0, size=0.1) +
# Top 6 Yard
geom_rect(xmin = -75, xmax = 75, ymin = 480, ymax = 515, color = "white", alpha=0, size=0.1) +
# Bottom 6 Yard
geom_rect(xmin = -75, xmax = 75, ymin = -515, ymax = -480, color = "white", alpha=0, size=0.1) +
# Top 18 Yard
geom_rect(xmin = -180, xmax = 180, ymin = 360, ymax = 515, color = "white", alpha=0, size=0.1) +
# Bottom 18 Yard
geom_rect(xmin = -180, xmax = 180, ymin = -515, ymax = -360, color = "white", alpha=0, size=0.1) +
# **** End of Pitch
geom_point(shape=16, size=5) +
xlim(-400,400) + ylim(-540,540) +
scale_color_manual(values=c("#ffff00", "#86cdea")) +
geom_text(aes(label=DataX$Position),hjust="middle", vjust="center", size=2)
gg_animate(p, interval = .1, "output.mp4")
一些DataX输出:
structure(list(Player = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L
), .Label = c("", "A.Guira", "A.Hjulsager", "D.Agger", "D.Boysen",
"F.Dickoh", "F.Holst", "F.R\xbfnnow", "J.Absalonsen", "J.Drachmann",
"J.Larsson", "K.Wilczek", "L.Phiri", "M.Albrechtsen", "M.DelHande",
"M.Pedersen", "M.Skender", "N.Madsen", "P.Joao", "P.Kanstrup",
"R.Austin", "R.Durmisi", "S.Kroon", "T.Bechmann"), class = "factor"),
Time_UpD = c(701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L,
709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L,
701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L,
702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L,
703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L,
704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L,
705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L,
706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L,
707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L,
708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L,
709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L,
701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L,
702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L,
703L, 704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L,
704L, 705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L,
705L, 706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L,
706L, 707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L,
707L, 708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L,
708L, 709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L,
709L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L
), Y_Location = c(-98L, -97L, -96L, -95L, -95L, -94L, -93L,
-92L, -91L, -260L, -262L, -267L, -270L, -272L, -277L, -278L,
-282L, -286L, -69L, -72L, -73L, -76L, -79L, -80L, -82L, -83L,
-86L, -405L, -402L, -401L, -398L, -396L, -395L, -394L, -394L,
-394L, 385L, 385L, 383L, 382L, 381L, 380L, 379L, 378L, 377L,
59L, 59L, 58L, 58L, 57L, 57L, 57L, 56L, 56L, -308L, -310L,
-313L, -316L, -318L, -320L, -322L, -324L, -327L, -120L, -120L,
-120L, -120L, -120L, -120L, -121L, -121L, -121L, -12L, -12L,
-11L, -10L, -10L, -9L, -9L, -8L, -7L, -172L, -173L, -175L,
-176L, -177L, -179L, -180L, -182L, -184L, -12L, -13L, -14L,
-15L, -16L, -17L, -17L, -17L, -18L, -177L, -177L, -178L,
-178L, -178L, -178L, -178L, -178L, -178L, -111L, -112L, -113L,
-115L, -116L, -117L, -118L, -120L, -122L, -160L, -161L, -163L,
-164L, -165L, -166L, -167L, -168L, -169L, 78L, 77L, 76L,
74L, 73L, 71L, 70L, 69L, 67L, -253L, -254L, -255L, -256L,
-256L, -257L, -257L, -257L, -256L, 13L, 14L, 15L, 16L, 16L,
17L, 17L, 18L, 19L, -160L, -159L, -157L, -155L, -154L, -152L,
-150L, -148L, -146L, -139L, -139L, -140L, -140L, -140L, -140L,
-141L, -141L, -141L, 94L, 94L, 93L, 92L, 92L, 91L, 91L, 90L,
89L, 55L, 55L, 54L, 53L, 53L, 53L, 53L, 53L, 52L, 71L, 70L,
70L, 69L, 69L, 69L, 68L, 68L, 68L), X_Location = c(66L, 68L,
72L, 76L, 79L, 83L, 85L, 89L, 93L, -100L, -102L, -106L, -109L,
-111L, -114L, -115L, -117L, -120L, -29L, -26L, -24L, -20L,
-16L, -14L, -10L, -8L, -4L, 99L, 104L, 107L, 111L, 114L,
115L, 116L, 116L, 115L, -4L, -4L, -3L, -2L, -1L, -1L, 0L,
1L, 2L, -172L, -171L, -170L, -169L, -169L, -168L, -167L,
-166L, -166L, 71L, 73L, 76L, 80L, 82L, 86L, 88L, 92L, 96L,
-198L, -197L, -196L, -194L, -193L, -191L, -190L, -188L, -186L,
135L, 136L, 137L, 139L, 140L, 142L, 142L, 144L, 146L, -62L,
-61L, -61L, -60L, -60L, -60L, -60L, -59L, -59L, 30L, 32L,
34L, 36L, 37L, 39L, 40L, 42L, 43L, 19L, 19L, 20L, 21L, 21L,
21L, 21L, 20L, 20L, -65L, -65L, -65L, -65L, -64L, -64L, -64L,
-64L, -65L, 150L, 154L, 157L, 160L, 163L, 166L, 169L, 172L,
175L, 56L, 56L, 57L, 58L, 58L, 58L, 59L, 59L, 60L, 185L,
190L, 192L, 197L, 202L, 205L, 210L, 213L, 218L, -210L, -211L,
-211L, -212L, -212L, -213L, -213L, -214L, -214L, -212L, -213L,
-215L, -217L, -218L, -220L, -222L, -224L, -227L, 41L, 42L,
45L, 47L, 48L, 50L, 51L, 53L, 55L, 42L, 43L, 44L, 46L, 47L,
49L, 50L, 52L, 54L, -44L, -43L, -40L, -38L, -37L, -35L, -33L,
-31L, -29L, -39L, -37L, -36L, -34L, -32L, -31L, -30L, -29L,
-27L), Team = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("", "BIF",
"SON"), class = "factor"), SquadNo = c(21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 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, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L), Position = structure(c(12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L), .Label = c("", "AM", "CF", "CM", "DM", "GK", "LB",
"LD", "LW", "RB", "RD", "RW"), class = "factor"), X = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), X.1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA), X.2 = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, 701L, 702L, 703L, 704L, 705L, 706L, 707L,
708L, 709L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA), X.3 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
-260L, -262L, -267L, -270L, -272L, -277L, -278L, -282L, -286L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
), X.4 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, -100L, -102L,
-106L, -109L, -111L, -114L, -115L, -117L, -120L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("Player",
"Time_UpD", "Y_Location", "X_Location", "Team", "SquadNo", "Position",
"X", "X.1", "X.2", "X.3", "X.4"), row.names = c(702L, 703L, 704L,
705L, 706L, 707L, 708L, 709L, 710L, 28535L, 28536L, 28537L, 28538L,
28539L, 28540L, 28541L, 28542L, 28543L, 56368L, 56369L, 56370L,
56371L, 56372L, 56373L, 56374L, 56375L, 56376L, 84201L, 84202L,
84203L, 84204L, 84205L, 84206L, 84207L, 84208L, 84209L, 112034L,
112035L, 112036L, 112037L, 112038L, 112039L, 112040L, 112041L,
112042L, 168739L, 168740L, 168741L, 168742L, 168743L, 168744L,
168745L, 168746L, 168747L, 196572L, 196573L, 196574L, 196575L,
196576L, 196577L, 196578L, 196579L, 196580L, 224405L, 224406L,
224407L, 224408L, 224409L, 224410L, 224411L, 224412L, 224413L,
252238L, 252239L, 252240L, 252241L, 252242L, 252243L, 252244L,
252245L, 252246L, 280071L, 280072L, 280073L, 280074L, 280075L,
280076L, 280077L, 280078L, 280079L, 307904L, 307905L, 307906L,
307907L, 307908L, 307909L, 307910L, 307911L, 307912L, 335737L,
335738L, 335739L, 335740L, 335741L, 335742L, 335743L, 335744L,
335745L, 363570L, 363571L, 363572L, 363573L, 363574L, 363575L,
363576L, 363577L, 363578L, 391403L, 391404L, 391405L, 391406L,
391407L, 391408L, 391409L, 391410L, 391411L, 419236L, 419237L,
419238L, 419239L, 419240L, 419241L, 419242L, 419243L, 419244L,
447069L, 447070L, 447071L, 447072L, 447073L, 447074L, 447075L,
447076L, 447077L, 474902L, 474903L, 474904L, 474905L, 474906L,
474907L, 474908L, 474909L, 474910L, 502735L, 502736L, 502737L,
502738L, 502739L, 502740L, 502741L, 502742L, 502743L, 530568L,
530569L, 530570L, 530571L, 530572L, 530573L, 530574L, 530575L,
530576L, 558401L, 558402L, 558403L, 558404L, 558405L, 558406L,
558407L, 558408L, 558409L, 586234L, 586235L, 586236L, 586237L,
586238L, 586239L, 586240L, 586241L, 586242L, 614067L, 614068L,
614069L, 614070L, 614071L, 614072L, 614073L, 614074L, 614075L
), class = "data.frame")
答案 0 :(得分:0)
不确定这是否是可接受的输出,但我认为它仍然可以告诉你的故事:
ggplot(DataX, aes(x=X_Location, y=Y_Location, frame = Time_UpD, color=Team)) +
theme(panel.background = element_rect(fill = "#359935", ), legend.position="none", panel.grid.major = element_blank(), panel.grid.minor = element_blank(),axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks = element_blank(),axis.title.x=element_blank(),axis.title.y=element_blank()) +
# **** Start of Pitch
# Top Half
geom_rect(xmin = -330, xmax = 330, ymin = 0, ymax = 515, color = "white", alpha=1, size=0.1) +
# Bottom Half
geom_rect(xmin = -330, xmax = 330, ymin = -515, ymax = 0, color = "white", alpha=1, size=0.1) +
# Top 6 Yard
geom_rect(xmin = -75, xmax = 75, ymin = 480, ymax = 515, color = "white", alpha=1, size=0.1) +
# Bottom 6 Yard
geom_rect(xmin = -75, xmax = 75, ymin = -515, ymax = -480, color = "white", alpha=1, size=0.1) +
# Top 18 Yard
geom_rect(xmin = -180, xmax = 180, ymin = 360, ymax = 515, color = "white", alpha=1, size=0.1) +
# Bottom 18 Yard
geom_rect(xmin = -180, xmax = 180, ymin = -515, ymax = -360, color = "white", alpha=1, size=0.1) +
# **** End of Pitch
#geom_point(shape=16, size=5) +
xlim(-400,400) + ylim(-540,540) +
scale_color_manual(values=c("#ffff00", "#86cdea")) +
geom_point(size = 7) +
geom_point(color = "white", size = 5) +
geom_text(aes(label=DataX$Position),hjust="middle", vjust="center", size=2)
实际上并不需要使用geom_point和geom_text / geom_label,因为它们只是使用不同的geom显示相同的坐标。我更喜欢geom_label而不是文本,因为它更容易阅读。
此外,您不需要将您的美学定义为'DataX $ abc',ggplot2已经了解您正在引用'DataX'数据框。