Remove extra space and ring at the edge of a polar plot

前端 未结 1 1797
面向向阳花
面向向阳花 2020-12-01 13:17

I have a polar plot in ggplot2 that I am getting pretty close in finishing (fairly simple plot). I have been able to get assistance in removing the rectangular

相关标签:
1条回答
  • 2020-12-01 13:46

    The extra space is generated by the outermost circle of a panel.grid. The grid is added by default in the theme you have used (and in most other ggplot themes; default settings here)

    Thus, remove panel.grid in theme. You might then create an own grid, according to taste, using e.g. geom_hline and geom_vline. Here I used the breaks you had specified in scale_x and _y as intercepts. I picked line colour and size from default panel.grid.major in theme_bw.

    ggplot(data = df) +
      geom_point(aes(x = bng, y = rng, color = det), size = 5, alpha = 0.7) +
      geom_hline(yintercept = seq(0, 15000, by = 3000), colour = "grey90", size = 0.2) +
      geom_vline(xintercept = seq(0, 360-1, by = 45), colour = "grey90", size = 0.2) +
      coord_polar(theta = 'x', start = 0, direction = 1) +
      labs(x = '', y = '') +
      scale_color_manual(name = '',
                         values = c('red', 'black'),
                         breaks = c(FALSE, TRUE),
                         labels = c('Not Detected', 'Detected')) +
      scale_x_continuous(limits = c(0, 360), expand = c(0, 0), breaks = seq(0, 360-1, by = 45)) +
      scale_y_continuous(limits = c(0, 15000), breaks = seq(0, 15000, by = 3000)) +
      theme_bw() +
      theme(panel.border = element_blank(),
            legend.key = element_blank(),
            axis.ticks = element_blank(),
            axis.text.y = element_blank(),
            panel.grid  = element_blank())
    

    enter image description here

    0 讨论(0)
提交回复
热议问题