How to change the histogram borderline thickness in ggplot geom_histogram()
Asked Answered
C

4

13

I have the following code:

library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(x=mpg)) + geom_histogram(bins=15, colour='red')

Which produce this:

enter image description here

As stated there, how can I change the thickness of the enclosing line of the histogram?

Clachan answered 15/3, 2017 at 1:22 Comment(2)
Best practice is to remove border lineCleanshaven
but you can use size=3Cleanshaven
P
23

Just use size argument

geom_histogram(bins=15, colour='red',size=2)
Pencil answered 15/3, 2017 at 1:27 Comment(0)
R
8

Easy enough :)

ggplot(mtcars, aes(x=mpg)) + geom_histogram(bins=15, colour='red',size=3)
Rawalpindi answered 15/3, 2017 at 1:27 Comment(0)
S
0

In addition, to program in point space, I used the following function:

MyPoints <- function(desired_points){
  return (unit(desired_points*.5*(1/1.07), "point"))
}

geom_histogram(size=MyPoints(1))
Szombathely answered 27/6, 2022 at 2:50 Comment(0)
B
0

Just tested on ggplot2, the size aesthetic for lines was deprecated in ggplot2 version 3.4.0.

You can do the same using linewidth.

ggplot(mtcars, aes(x=mpg)) + 
    geom_histogram(bins=15, colour='red', linewidth=0.2)
Bushel answered 14/8 at 6:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.