Can geom_line be added to geom_step() in the same graph

I work with pulsed data, I need to add a the experimental data over square waves.
I know I can draw these in ggplot with geom_segment, but the number of them makes that an unreasonable thing to do.
I want to know if there is a way that I could add either geom_line()/geom_point() to a geom_step()?

Below is my reprex :crazy_face:

library(tidyverse)
d <- data.frame(stage_number=gl(5, 2), Time=1:10, Voltage=runif(10, min=0, max=1000), active=rep(c("","*"),5))

df<-d %>% 
  split(.$stage_number) %>% 
  map(~add_row(., stage_number=unique(.$stage_number), Time=0, Voltage=1000, active="")) %>% 
  map(~add_row(., stage_number=unique(.$stage_number), Time=2100, Voltage=0, active="")) %>% 
  bind_rows()%>%
  arrange(stage_number,Time)
df3<-df%>%
  filter(active=='')
ggplot(df3, aes(x=Time, y=Voltage, col=stage_number))+
         geom_step()

Main=data.frame(Time=c(0:1998, by=1),
                Voltage=c( rep(c(0,1), 250), rep(c(1000,1005),250),rep(c(1,0), 250), rep(c(1000,1005), 250))
)

ggplot(Main,aes(x=Time, y=Voltage))+
  geom_point()+
  geom_step(aes(x=df3$Time, y=df3$Voltage, col=df3$stage_number))

Thanks for any advice that you can provide.

extending your step graph code, to add the points you want

ggplot(df3, aes(x=Time, y=Voltage, col=stage_number))+
  geom_step() + 
  geom_point(data = Main,
             aes(x=Time, y=Voltage,col=NULL))

That works for me can you explain why mine does not work, it is because of the col=NULL is not there, and why is that important.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.