繁体   English   中英

Plot 一步(分段常数) function in R

[英]Plot a step (piecewise constant) function in R

假设您有以下示例数据集:

rm(list=ls()); set.seed(1)
start<-c(0:4); stop<-c(1:5); Response<- round(10*runif(5) )
Dat<-data.frame(start,stop,Response)
Dat
  start stop Response
1     0    1 3
2     1    2 4
3     2    3 6
4     3    4 9
5     4    5 2

开始/停止是 x 轴。 如何在 R 中制作 plot 以便在某个开始和停止之间 y 轴采用恒定值作为响应。 即从时间 0 到 1,y 轴取值 3,...,从时间 4 到 5,y 轴取值 2。

这些都是你要找的吗?

library(ggplot2)

Dat %>% 
    ggplot(aes(start, Response)) +
    geom_step()

Dat %>% 
    ggplot() +
    geom_segment(aes(x = start, xend = stop, y = Response, yend = Response)) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM