代码之家  ›  专栏  ›  技术社区  ›  Jack Armstrong

调整打印边距或创建半圆

  •  1
  • Jack Armstrong  · 技术社区  · 6 年前

    我想创建下面的图像。但是,我需要把场地中间的圆改成一个半圆,或者找到一个这样的方法 ggplot

    我试过调整边距,研究如何制作一个半圆,但我只找到了所有圆的绘图,然后将这些圆转换为极坐标。

    代码:

    p <- 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_point(aes(x = 50, y = 50), colour = "black", size = 55, shape = 1) + #centre circle 
      geom_rect(aes(xmin=49, xmax=50,ymin=0,ymax=100),fill='white',color='white',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")
      )
      p
    

    enter image description here

    2 回复  |  直到 6 年前
        1
  •  1
  •   Z.Lin    6 年前

    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

    注:我对体育一无所知;不知道该字段的适当维度应该是什么。您可能需要调整值以使圆看起来像圆形。。。

        2
  •  0
  •   Rekyt    6 年前

    ggsoccer 还可以绘制足球场(包不在CRAN上,但在Github上)