Commit 52b0312f authored by Takumi Amano's avatar Takumi Amano 💬
Browse files

[add] ヒートマップとサッカーフィールドの描写できるようにした

parent 45d1390d
get_kick_point <- function(log_data) {
output <- log_data |>
dplyr::filter(command=="kick") |>
dplyr::mutate(
x = args |> stringr::str_extract("[0-9\\-\\.]+"),
l1 = args |> stringr::str_remove(x),
y = l1 |> stringr::str_extract("[0-9\\-\\.]+"),
) |>
dplyr::select(
step,
team,
unum,
command,
x,
y,
)
return(output)
}
make_graph <- function(p_data,teamname,num){
p <- ggplot(data = p_data %>% filter(team==teamname,unum==num), aes(x = as.numeric(x), y = as.numeric(y))) +
ggplot2::coord_fixed(xlim=c(-55,55),ylim =c(-35,35))+
geom_hline(yintercept = -34.1, linetype = "solid")+
geom_hline(yintercept = 34.1, linetype = "solid")+
DEFAULT_MAX_PLAYER <- 11
DEFAULT_PITCH_LENGTH <- 105.0
DEFAULT_PITCH_WIDTH <- 70.0
DEFAULT_PITCH_MARGIN <- 5.0
DEFAULT_CENTER_CIRCLE_R <- 9.15
DEFAULT_PENALTY_AREA_LENGTH <- 16.5
DEFAULT_PENALTY_AREA_WIDTH <- 40.32
DEFAULT_PENALTY_CIRCLE_R <- 9.15
DEFAULT_PENALTY_SPOT_DIST <- 11.0
DEFAULT_GOAL_AREA_LENGTH <- 5.5
DEFAULT_GOAL_AREA_WIDTH <- 18.32
DEFAULT_GOAL_DEPTH <- 2.44
# DEFAULT_CORNER_ARC_R <- 1.0
half_p_l <- DEFAULT_PITCH_LENGTH/2
half_p_w <- DEFAULT_PITCH_WIDTH/2
penalty_x <- half_p_l - DEFAULT_PENALTY_AREA_LENGTH
penalty_y <- DEFAULT_PENALTY_AREA_WIDTH/2
goal_x <- half_p_l - DEFAULT_GOAL_AREA_LENGTH
goal_y <- DEFAULT_GOAL_AREA_WIDTH/2
make_field <- function(input_graph){
p <- input_graph +
geom_hline(yintercept = 0, linetype = "solid")+
geom_vline(xintercept = 52.6, linetype = "solid")+
geom_vline(xintercept = -52.6, linetype = "solid")+
geom_vline(xintercept = 0, linetype = "solid")+
geom_linerange(aes(x=half_p_l, y=NULL, ymin=-half_p_w, ymax=half_p_w))+
geom_linerange(aes(x=-half_p_l, y=NULL, ymin=-half_p_w, ymax=half_p_w))+
geom_linerange(aes(x=NULL, y=half_p_w, xmin=-half_p_l, xmax=half_p_l))+
geom_linerange(aes(x=NULL, y=-half_p_w, xmin=-half_p_l, xmax=half_p_l))+
geom_point(size=0.1) +
geom_density_2d_filled(alpha = 0.7)
geom_linerange(aes(x=penalty_x, y=NULL, ymin=-penalty_y, ymax=penalty_y))+
geom_linerange(aes(x=-penalty_x, y=NULL, ymin=-penalty_y, ymax=penalty_y))+
geom_linerange(aes(x=NULL, y=penalty_y, xmin=penalty_x, xmax=half_p_l))+
geom_linerange(aes(x=NULL, y=-penalty_y, xmin=penalty_x, xmax=half_p_l))+
geom_linerange(aes(x=NULL, y=penalty_y, xmax=-penalty_x, xmin=-half_p_l))+
geom_linerange(aes(x=NULL, y=-penalty_y, xmax=-penalty_x, xmin=-half_p_l))+
geom_linerange(aes(x=goal_x, y=NULL, ymin=-goal_y, ymax=goal_y))+
geom_linerange(aes(x=-goal_x, y=NULL, ymin=-goal_y, ymax=goal_y))+
geom_linerange(aes(x=NULL, y=goal_y, xmax=goal_x, xmin=half_p_l))+
geom_linerange(aes(x=NULL, y=-goal_y, xmax=goal_x, xmin=half_p_l))+
geom_linerange(aes(x=NULL, y=goal_y, xmin=-goal_x, xmax=-half_p_l))+
geom_linerange(aes(x=NULL, y=-goal_y, xmin=-goal_x, xmax=-half_p_l))+
ggforce::geom_circle(aes(x0 = 0, y0 = 0, r = DEFAULT_CENTER_CIRCLE_R),inherit.aes = FALSE)
return(p)
}
#ggplot2::geom_path(size=1.2,aes(color = as.numeric(step))) +
# +
# ggplot2::geom_density2d(size = 0.25, colour = "black")
\ No newline at end of file
make_heatmap <- function(p_data){
p <- ggplot(data = p_data, aes(x = as.numeric(x), y = as.numeric(y))) +
ggplot2::coord_fixed(xlim=c(-half_p_l,half_p_l),ylim =c(-half_p_w,half_p_w))+
geom_density_2d_filled(alpha = 0.5)
p <- p |> make_field()
return(p)
}
# make_kick_point <- function(p_data,input_graph){
# log_data <- p_data
# p <- input_graph +
# geom_point(data = p_data,aes(x = as.numeric(x), y = as.numeric(y)))
# return(p)
# }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment