简体   繁体   English

如何在R中绘制这样的图形?

[英]How to plot such a graph in R?

I've data in a csv file with the following format : 我在csv文件中的数据具有以下格式:

start;duration
1;4
7;3
15;2

that's means we have 3 tasks, the first start at 1 and takes 4 seconds (so it end at 5), the second start a 7 and takes 3 second (soo ended at 10) and the last starts at 15 and take 2 seconds 这意味着我们有3个任务,第一个从1开始,需要4秒(所以它以5结束),第二个开始7并且需要3秒(soo结束于10),最后一个从15开始并需要2秒

How to reprensent these information in a graph which look like this 如何在这样的图表中重新呈现这些信息 在此输入图像描述

 dat <- read.csv2(text="start;duration
 1;4
 7;3
 15;2
 ")
 plot(NA, xlim=c(0,20), ylim=c(0,9), ylab="",xlab="X", xaxt="n", yaxt="n")
 with(dat, segments(x0=start, x1=start+duration, y0=2,y1=2))
 with(dat, text( start+duration/2, 2.5, labels=duration))
 axis(1, at=seq(0,20,by=2), labels=seq(0,20,by=2))

You could obviously put in more descriptive labels for ylab and xlab in the plot call but this is what you get with that minimal example: 显然,您可以在绘图调用中为ylab和xlab添加更多描述性标签,但这是您使用该最小示例获得的内容:

在此输入图像描述

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

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