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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top