Question

How can I use ggplot2's geom_line to plot a square function, where x,y coordinates are connected by squares rather than by lines?

Something that looks like:

enter image description here

Is this possible?

Était-ce utile?

La solution

For this you can use geom_step:

df = data.frame(x = 1:10, 
                y = sample(c(1,2), 10, replace = TRUE))
ggplot(df, aes(x = x, y = y)) + geom_step()

enter image description here

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top