r - 绘制半个数据集而不是整个记录
问题描述
我有记录期在 1966 年到 2019 年之间的数据集。我想绘制 1966 年到 1990 年之间的图表。我会使用什么命令?
解决方案
ggplot2
有多种方法来限制轴限制。首先,我们需要一些示例数据:
expl <- data.frame(year = rep(1966:2021, 3),
value = c(replicate(3, cumsum(rnorm(56, sd = .1)))),
id = gl(3,56))
library(ggplot2)
ggplot(expl) +
geom_line(aes(x = year, y = value, color = id)) +
ggtitle("full plot")
限制轴限制的一种方法coord_cartesian
是
ggplot(expl) +
geom_line(aes(x = year, y = value, color = id)) +
ggtitle("restricted x axis") +
coord_cartesian(xlim = c(1966, 1990))
推荐阅读
- cpanel - 保护 VPS、WHM、cPanel
- python - 在使用 QSortFilterProxyModel 的 QTreeView 中插入行
- python - 在字典的字典中查找计数最高的元素
- r - 如何增加 RStudio 中 R Notebook 中显示的列数?
- html - 如何将图像居中到我的标题左侧?
- c - 将包含科学计数法数字的字符串矩阵转换为单行数组
- sql - 使用 LEFT OUTER JOIN 选择并以逗号分隔的列表形式返回
- java - volley.parsererror:org.json.JSONException:java.lang.string 类型的值 br 无法转换为 JSONObject
- java - 禁用时 EditText 恢复为灰色文本
- excel - VBA excel - range.formula 问题