Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change thickness median line geom_boxplot()

Tags:

r

ggplot2

boxplot

I want to do some modifications of a geom_boxplot(). Because my boxplots are really "small" sometimes (see yellow and green clade in the graphic here) i want to highlight the median even more. so is it possible to adjust the thickness of the median line?

like image 881
Zoidie Avatar asked Sep 18 '12 11:09

Zoidie


1 Answers

This solution is not obvious from the documentation, but luckily does not require us to edit the source code of ggplot2. After digging through the source of ggplot2 I found that the thickness of the median line is controlled by the fatten parameter. By default fatten has a value of two:

require(reshape)
require(ggplot2)
cars_melt = melt(cars)

ggplot(aes(x = variable, y = value), data = cars_melt) + 
  geom_boxplot(fatten = 2) 

enter image description here

But if we increase the value to for example 4, the median line becomes thicker.

ggplot(aes(x = variable, y = value), data = cars_melt) + 
  geom_boxplot(fatten = 4) 

enter image description here

like image 51
Paul Hiemstra Avatar answered Sep 24 '22 11:09

Paul Hiemstra