histogram without vertical lines
Asked Answered
P

2

8

When I create a histogram, it looks a lot like this:

set.seed(1)
x <- 1:100
y <- x + rnorm(50)
y=round(y)
hist(y)

Is there a way to make a histogram look a bit like this? I can only get a histogram with bins, which I don't need for my plot. heatmap

I don't want the black bins, I actually only want the blue, green and red lines. Can stackoverflow point me in the right direction?

Progression answered 17/5, 2011 at 12:20 Comment(2)
are the blue, red, and green lines density curves? Some sample data would help as well.Verbiage
Yeah, all of them are density curvesProgression
N
12

Put your histogram in an object, and use type="s" to get the stepwise plot :

x <- rnorm(1000)
y <- hist(x)
plot(y$breaks,
      c(y$counts,0)
   ,type="s",col="blue")

gives : enter image description here

Numerator answered 17/5, 2011 at 12:36 Comment(1)
That's exactly what i'm looking for (now let's try this out)Progression
P
0

If you want to keep the (eventual) coloring of you histogram, you can deactivate the border and add it yourself on top.

x <- rnorm(1000)
h <- hist(x, col="royalblue", border=NA, freq = T)

lines(rep(h$breaks, each=2)[-c(1,2*length(h$breaks))], 
      rep(h$counts, each=2), lwd=2)

# replace h$counts by h$density if freq=F

enter image description here

Persuader answered 15/6, 2018 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.