16

Using ggplot's geom_pointrange() function, how do I change the size of the point and the thickness of the line separately?

Example:

# make test data
df <- data.frame(y=10, ymin=1, ymax=20, x=1)

# store ggplot object
p <- ggplot(data=df, aes(y=y, ymin=ymin, ymax=ymax, x=x)) 

# plot 1: big dot and thick line
p + geom_pointrange(fill='blue', color='grey', shape=21, size=5)

# plot 2: small dot and thin line (I want small dot and thick line or vice versa)
p + geom_pointrange(fill='blue', color='grey', shape=21, lwd=1, size=5)

Plot 1:

enter image description here

Plot 2:

enter image description here

Can I get a small dot with a thick line (or vice-versa)?

A workaround might be to plot the line and point as separate geoms using geom_point and geom_errorbar. Unfortunately, my real application involves jittering, so the point and the interval end up in different places (unless maybe I can control the jittering?).

I can find similar questions on SO (like this), but they don't directly answer this one.

Thanks!

Community
  • 1
  • 1
dmp
  • 815
  • 1
  • 6
  • 19

1 Answers1

27

You can use fatten in combination with size:

p + geom_pointrange(fill='blue', color='grey', shape=21, fatten = 20, size = 5)

enter image description here

p + geom_pointrange(fill='blue', color='grey', shape=21, fatten = .5, size = 5)

enter image description here

s. ?geom_pointrange:

fatten
A multiplicative factor used to increase the size of the middle bar in geom_crossbar() and the middle point in geom_pointrange().

erc
  • 10,113
  • 11
  • 57
  • 88
  • 1
    Interestingly, `fatten` seems to work in Windows but not my Unix environment. Any thoughts? – dmp Jun 01 '16 at 21:49
  • 1
    I tried on a Mac, no idea what the problem could be, maybe your R and ggplot2 version need to be updated? – erc Jun 02 '16 at 05:03
  • I receive the 'ignoring unknown aesthetics: fatten" on my Mac too... – derelict Jun 12 '20 at 14:44
  • @dmp @Derelict Have you added `fatten` outside the `aes(...)`? With `aes(..., fatten = 1)`, I get the same error message. – A.Koe Oct 22 '21 at 13:13