r - 使用 ggplot2 根据值的间隔生成条形图
问题描述
我有以下 R 数据表:
library(data.table)
dt1 = data.table(start = c(0, 3, 5, 7), end = c(3, 5, 7, 10), size = c(0, 3, 2, 1))
print(dt1)
start end size
1: 0 3 0
2: 3 5 3
3: 5 7 2
4: 7 10 1
我想用 ggplot2 绘制一个条形图,其中每个间隔都由size
. 有没有明确的方法来实现这一点ggplot2
?
foo = data.table(x = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
size = c(0, 0, 0, 3, 3, 3, 2, 2, 1, 1, 1))
ggplot(data=foo, aes(x=x, y=size)) + geom_bar(stat="identity")
这大致是我的想法,但不正确。从 3 到 5 的间隔应该是一条实线,而不是三条线。
这是 ggplot2 的标准程序吗?
解决方案
推荐阅读
- graphql - 如何使用 apollo 2 从端点文件进行自省?
- rest - REST - 删除后使用 HTTP 缓存获取集合
- awk - 有没有办法匹配文件中的字符串并在字符串匹配后的下一行打印/附加另一个文件(单行)的内容
- android - 将领域与协程一起使用时从不正确的线程访问领域
- react-native - 如何避免 JavaScript 对象数组合并中的覆盖
- python - Python 正则表达式 - 在某些值上拆分字符串,但不是全部
- spring - Spring Cloud Kubernetes - Spring Boot 不读取配置图
- javascript - 盖茨比 - 覆盖图像
- c - 如何从整数之前的文件中读取字符串
- ios - Xcode 10 无法下载配置文件