r - R:错误:美学必须是长度 1 或与数据相同:x
问题描述
library(ggplot2)
mydata <- data.frame(variable = c(1, 1, 1, 2, 2, 2),
value = c(1, 2, 3, 4, 5, 6))
p <- ggplot(data = mydata, aes(x = 1:3, y = value, group = variable, color = variable)) + geom_line()
> p
Error: Aesthetics must be either length 1 or the same as the data (6): x
运行上面的代码给了我错误:Error: Aesthetics must be either length 1 or the same as the data (6): x
. 我认为这与我x = 3
在aes
. 我想要绘制的样子是这样的:
解决方案
您的图表图像的 x 轴标记为“迭代”,但该信息未包含在“mydata”的示例中。如果没有这些缺失的信息,将很难为您提供帮助。
根据您的评论,您可能对设置x 轴的限制感兴趣。在这种情况下,您可以尝试使用类似的东西。
p2 <- ggplot(data = mydata, aes(x = variable, y = value)) +
geom_line() +
xlim(1,3)
p2
推荐阅读
- python - 在 tkinter 中触发两个命令的单个按钮
- python - 如何使用 networkx + python 枚举图中的所有 *maximal* 集团?
- wordpress - 我们可以在 WordPress 中为自定义帖子类型主题后端添加帖子表单吗?
- azure - 使用 powershell 为 AppService Web 应用程序中的所有插槽设置 IP 限制
- excel - 如何正确地将“是/否”添加到具有现有字符串的 VBA 消息框中
- package-managers - 在 14.2 的 Slackware 中安装 AIDE
- regex - 没有前瞻和回溯的正则表达式(golang包不允许)
- listview - Flutter ListView.builder() 动态列表 - 显示无限重复的条目
- sql - 将带有冒号“:”的字符串添加到“tsvector”数据类型时出错
- django - 如何在文本字段中创建新行?