- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试将geom_ribbon
对象添加到我的ggplot2
图中。在我的数据框中,我有NA
值(我想)可能会引起问题。这是我拥有的数据帧的可复制示例:
base <- c(1:10, rep(NA, 10))
output1 <- c(rep(NA, 9), 10 - 0:10)
output2 <- c(rep(NA, 9), 10 + 0:10)
xaxis <- 1:20
df <- data.frame(xaxis, base, output1, output2)
df
xaxis base output1 output2
1 1 1 NA NA
2 2 2 NA NA
3 3 3 NA NA
4 4 4 NA NA
5 5 5 NA NA
6 6 6 NA NA
7 7 7 NA NA
8 8 8 NA NA
9 9 9 NA NA
10 10 10 10 10
11 11 NA 9 11
12 12 NA 8 12
13 13 NA 7 13
14 14 NA 6 14
15 15 NA 5 15
16 16 NA 4 16
17 17 NA 3 17
18 18 NA 2 18
19 19 NA 1 19
20 20 NA 0 20
ggplot2
绘制
geom_ribbon
对象:
dfm <- melt(df, id=1)
ggplot(dfm, aes(x = xaxis, y = value, colour = variable)) +
geom_line(aes(group=variable)) +
geom_ribbon(data=df, aes(group = 1, ymin=output1, ymax=output2))
Error in eval(expr, envir, enclos) : object 'variable' not found
最佳答案
之所以出现此错误,是因为variable
用于aes()
函数的ggplot()
中的颜色。当您将geom_ribbon()
与新数据框添加在一起时,geom_ribbon()
会尝试在新数据框中查找variable
以将其用于颜色。要忽略此变量,请在inherit.aes=FALSE
内添加geom_ribbon()
-因此,您要告知所有参数都应独立使用-这样,您应该在x=xaxis
中再次设置geom_ribbon()
。
ggplot(dfm, aes(x = xaxis, y = value, colour = variable)) +
geom_line(aes(group=variable)) +
geom_ribbon(data=df, aes(group = 1, x = xaxis,ymin=output1, ymax=output2),
inherit.aes=FALSE)
关于r - geom_ribbon不起作用-eval(expr,envir,enclos): object 'variable' not found中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19891637/
编辑以提供完整的代码示例和特定问题 我正在编写一个函数来生成股票价格的时间序列图。但是,出现以下错误 eval(expr,envir,enclos)中的错误:找不到对象'df1234' 这是该函数的示
我不明白这里出了什么问题。 data.train <- read.table("Assign2.WineComplete.csv",sep=",",header=T) # Building decis
我不明白这里出了什么问题。 data.train 。您需要更改公式或数据框,使它们彼此一致。 澄清一下:Pre 是一个包含公式的对象。该公式包含对变量 pre 的引用。后者必须与数据框一致。 关于r
我正在解决 Kaggle 数字识别器问题。当我尝试给定的代码时,出现错误。 eval(expr,envir,enclos)中的错误:找不到函数“eval” library(ggplot2) libra
当我尝试“编织 HTML”或使用 LyX 生成 pdf 时,我遇到了环境问题。当我直接运行 R 代码(或用 Rstudio 编译 HTML 笔记本)时,没问题。我已经用 knitr@1.3.7(开发版
我尝试将geom_ribbon对象添加到我的ggplot2图中。在我的数据框中,我有NA值(我想)可能会引起问题。这是我拥有的数据帧的可复制示例: base <- c(1:10, rep(NA, 10
我基于 kind help 在 R 中创建了一个函数来自@Jim M。 当我运行该函数时,出现错误:错误:未知列“原始数据” 查看调试器时,我收到消息: Rcpp::eval(expr, envir,
我试图复制 ggplot2 书第 86 页上 Hadley Wickham 的例子,在那里他覆盖了 geom_rects,显示执政党对失业趋势的影响。这是我的核心代码,包含一些示例数据: librar
我不明白为什么我的极简封装函数会产生主题错误。下面应该重现它。我的目标是根据单个数据框中的数据绘制一堆图,每个图都位于一个新窗口中。 library(ggplot2) library(datasets
下面显示的 R 代码是一个最小的工作示例,用于重现我不能说我理解的错误。运行脚本应该会产生错误,Error in eval(expr, envir, enclos) : could not find
下面显示的 R 代码是一个最小的工作示例,用于重现我不能说我理解的错误。运行脚本应该会产生错误,Error in eval(expr, envir, enclos) : could not find
当使用带有 boost/regex 的 Rcpp 时,Build&reload 显示 Error in eval(expr, envir, enclos) : object 'libboost_reg
我是一名优秀的程序员,十分优秀!