0

I'm trying to get a hollow point to have the same line type as an associated line range. For instance

library(tidyverse)

data.frame(
    x = letters[1:2] %>% 
      factor,
    ymin = 4:5,
    y = 5:6,
    ymax = 6:7
  ) %>% 
  ggplot() +
  geom_linerange(
    aes(x, ymin = ymin, ymax = ymax),
    linetype = "dashed"
  ) +
  geom_point(
    aes(x = x, y = y),
    shape = 21,
    size = 10,
    fill = "grey95",
    linetype = "dashed"
    ) +
  theme_void()

returns this

pointrange

How so I get the points' borders to also be dashed?

tomw
  • 3,114
  • 4
  • 29
  • 51
  • 1
    I believe shapes of central pieces in `geom_linerange` is limited to these shapes: https://github.com/tidyverse/ggplot2/blob/master/R/geom-point.r#L140 – Roman Luštrik Oct 22 '18 at 19:35
  • I'm using `geom_point()` for the middle part – tomw Oct 22 '18 at 19:44
  • The function I link to is used by `geom_point` as well. You may have to implement some sort of graphics to achieve a dashed circle. Something along the lines of https://stackoverflow.com/questions/27637455/display-custom-image-as-geom-point – Roman Luštrik Oct 22 '18 at 19:48
  • 1
    Maybe use 'dotted circle' unicode symbol (`"\u25CC"`) as shape, or [draw circles with desired `linetype`](https://stackoverflow.com/questions/6862742/draw-a-circle-with-ggplot2) – Henrik Oct 22 '18 at 19:52
  • @Henrik `ggforce::geom_circle()` is an elegant solution--if you add that as an answer I'll accept it. – tomw Oct 22 '18 at 20:01
  • 1
    @tomw Feel free to provide a self-answer! Cheers – Henrik Oct 22 '18 at 20:03
  • BTW, I'm having trouble with `ggforce::geom_circle` on this data frame. When I use `ggforce::geom_circle(aes(x0 = x2, y0 = y, r = 0.1), fill = "grey95", linetype = "dashed")` I get a warning and no circle. Works if we override factor x with `aes(x0 = 1:2, y0 = y, r = 0.1)`. – Jon Spring Oct 22 '18 at 20:06

1 Answers1

1

with thanks to @Henrik, ggforce::geom_circle() has the necessary functionality

tomw
  • 3,114
  • 4
  • 29
  • 51