Pregunta

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?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top