调整绘图边距或创建半圆

时间:2018-10-08 08:25:36

标签: r ggplot2

我想在下面创建图片。但是,我需要将字段中间的圆更改为仅半圆,或者找到一种方法,使face保存图像而没有任何空白。

我尝试过调整边距,并研究了如何制作半圆,但是我只找到了所有圆都被转换成极坐标的图。

代码:

face_recognition.face_encodings(np_arr)[0]

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以使用ggforce软件包中的geom_arc()创建半圆。

library(ggforce)

ggplot() +
  #Pitch
  geom_rect(aes(xmin = 100, xmax = 101, ymin = 44.7, ymax = 55.1), fill = NA, colour = "black", size = 1) + # Goal
  geom_rect(aes(xmin = 50, xmax = 100, ymin = 0, ymax = 100), fill = NA, colour = "black", size = 1) + # Field Around
  geom_rect(aes(xmin = 83, xmax = 100, ymin = 21, ymax = 79), fill = NA, colour = "black", size = 1) + #18yrd box
  geom_rect(aes(xmin = 100, xmax = 94, ymin = 36.8, ymax = 63.2), fill = NA, colour = "black", size = 1) + #6yrd box
  geom_point(aes(x = 88.5, y = 50), colour = "black", size = 1.5) + #PK spot
  geom_point(aes(x = 50, y = 50), colour = "black", size = 2) + #Centre circle dot

  geom_arc(aes(x0 = 50, y0 = 50, r = 22.5, start = 0, end = 180), size = 1) +

  coord_flip() +
  xlim(50, 101) +
  ylim(0,100)+
  #Theme
  theme(
    panel.background = element_rect(fill = "transparent",colour = NA),
    plot.margin = unit(c(0,0,0,0), "cm"),
    plot.title = element_text(size = 14, hjust = 0.5, vjust = 1.25),
    plot.background = element_rect(fill = "transparent", colour = NA),
    line = element_blank(),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text = element_blank(),
    legend.position = "none",
    legend.box = "vertical",
    legend.background = element_rect(fill = "transparent")
  )

plot

注意:我对运动一无所知,也不知道该领域的合适尺寸。您可能需要调整值以使圆看起来圆...

答案 1 :(得分:0)

ggsoccer也可以绘制足球场(该程序包不在CRAN上,但在Github上)