1

I am making a plot with ggplot2 in R and I want to change the thickness of my dots. I am using circles without a center (shape = 1) and I want to change the thickness of the lines. How do I do this, please? I am using geom_point

Size changes how large the dot/circle is, it does not charge how thick of a border there is around the dot

c6user
  • 55
  • 8

1 Answers1

2

This answer was inspired in the accepted answer to a similar question.

Use aesthetics stroke with small values, either zero or close to zero such as 0.1.

df <- data.frame(x = rep(0, 4), y = rep(0, 4), stroke = (0:3)/4)

ggplot(df) + 
  geom_point(aes(x, y, stroke = stroke),
             shape = 1,
             size = 20, colour = 'red') +
  facet_wrap(~ stroke)

enter image description here


Edit

Answering the comments below, here is an example of the use of scale_discrete_manual to change the stroke.

suppressPackageStartupMessages({
  library(ggplot2)
  library(dplyr)
})

df <- data.frame(x = rep(0, 4), y = rep(0, 4), stroke = (0:3)/4)

f <- factor(df$stroke)
vals <- setNames(c(3, 2, 4, 1), f)

df %>%
  mutate(stroke = factor(stroke)) %>%
  ggplot() + 
  geom_point(aes(x, y, stroke = stroke),
             shape = 1,
             size = 20, colour = 'red') +
  scale_discrete_manual(aesthetics = "stroke", values = vals) +
  facet_wrap(~ stroke)

Created on 2023-03-08 with reprex v2.0.2

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • Is there a way to scale the strokes? Like `scale_stroke_manual`? – drmariod Mar 07 '23 at 14:35
  • 1
    @drmariod You can use [`scale_discrete_manual`](https://github.com/tidyverse/ggplot2/issues/3507#issuecomment-526212978) with `aesthetics = "stroke"` and then change the `values` argument. – Rui Barradas Mar 07 '23 at 17:02
  • Cool, might be interesting to update your post to include this... But your answer did not get the deserved likes yet. :-( – drmariod Mar 08 '23 at 07:47