0

我一直在研究一些足球数据,并遇到了 alpha 美学使用的问题。基本上,我尝试在此处创建的足球场上绘制一些传球:https ://github.com/FCrSTATS/Visualisations/blob/master/3.CreateAPitch.md 但是,在使用 geom_segment 和 alpha 美学这样做时,我最终得到了当 alpha 小于 1 时没有线条,只绘制箭头。什么原因?它是在前面提到的链接的函数中定义的主题吗?我用过的代码:

pitch <- createPitch(10600, 7040, "#202020", "#797876", "#202020", "#131313")

pitch + geom_segment(data = data,
                 aes(x = x/100 * xmax, y = y/100 * ymax, 
                     xend = as.numeric(as.character(pass_end_x))/100 * xmax, 
                     yend = as.numeric(as.character(pass_end_y))/100 * ymax,
                     alpha = data$n/max(data$n)),
                 color = "blue", 
                 arrow = arrow(length = unit(0.3, "cm"), ends = 'first', type = 'closed'))

和数据:

structure(list(x = c(77.076, 66.7944444444444, 60.425, 64.7828571428571
), y = c(77.672, 19.0888888888889, 52.8055555555556, 90.0485714285714
), pass_end_x = c(88.296, 77.8240740740741, 70.0472222222222, 
73.5857142857143), pass_end_y = c(61.204, 20.7796296296296, 
64.0083333333333, 89.8485714285714), n = c(25L, 54L, 36L, 35L)), .Names = 
c("x", "y", "pass_end_x", "pass_end_y", "n"), row.names = c(NA, -4L), class 
= c("tbl_df", "tbl", "data.frame"))
4

1 回答 1

1

忽略音高部分,摆脱$作品就好了:

dd = structure(list(x = c(77.076, 66.7944444444444, 60.425, 64.7828571428571
), y = c(77.672, 19.0888888888889, 52.8055555555556, 90.0485714285714
), pass_end_x = c(88.296, 77.8240740740741, 70.0472222222222, 
73.5857142857143), pass_end_y = c(61.204, 20.7796296296296, 
64.0083333333333, 89.8485714285714), n = c(25L, 54L, 36L, 35L)), .Names = 
c("x", "y", "pass_end_x", "pass_end_y", "n"), row.names = c(NA, -4L), class 
= c("tbl_df", "tbl", "data.frame"))

xmax = ymax = 1

p = ggplot(
    dd,
    aes(
        x = x / 100 * xmax,
        y = y / 100 * ymax,
        xend = as.numeric(as.character(pass_end_x)) / 100 * xmax,
        yend = as.numeric(as.character(pass_end_y)) / 100 * ymax,
        alpha = n / max(n)
    )
) +
    geom_segment(color = "blue",
                             arrow = arrow(
                                length = unit(0.3, "cm"),
                                ends = 'first',
                                type = 'closed'
                             ))

p

在此处输入图像描述

您可以很容易地看到透明度差异。从您的链接添加主题仍然可以:

p + theme_blankPitch()

在此处输入图像描述

由于您的颜色选择,从您的问题中添加音高会使线条更难看到,但它们仍然存在:

pitch <- createPitch(10600, 7040, "#202020", "#797876", "#202020", "#131313")
pitch + geom_segment(data = dd,
    aes(
        x = x / 100 * xmax,
        y = y / 100 * ymax,
        xend = as.numeric(as.character(pass_end_x)) / 100 * xmax,
        yend = as.numeric(as.character(pass_end_y)) / 100 * ymax,
        alpha = n / max(n)
    ), color = "blue",
                             arrow = arrow(
                                length = unit(0.3, "cm"),
                                ends = 'first',
                                type = 'closed'
                             ))

在此处输入图像描述

如果您增加段的大小(例如size = 1.5),它们会更清晰一些,但我会推荐不同的颜色选择。您可以进行的另一项调整是设置 的限制scale_alpha_continuous以使范围的最小值更加不透明。默认最小值为 0.1,您可以将其提高到 0.2 甚至更高。

于 2018-03-10T19:44:00.557 回答