我正在使用长格式的数据框来创建面板密度图lattice。现在我想在每个面板内的中值 x 值处添加一条垂直线。dotplot我在(http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-中找到了这样做的建议with-log-scale-td4632513.html),但这对我不起作用。这是我的代码:
data(Chem97, package="mlmRev")
densityplot(~gcsescore | factor(score), data=Chem97,
panel=function(...){
panel.densityplot(...)
median.values <- median(x)
panel.abline(v=median.values, col.line="red")
})
Run Code Online (Sandbox Code Playgroud)
错误是:Object x not found。所以我尝试了以下方法:
panel=function(x,...){
panel.densityplot(...)
}
Run Code Online (Sandbox Code Playgroud)
当我将x参数添加到面板函数时,我收到错误Error using packet 1 (2, 3 etc.). x is missing。
出了什么问题?
我终于找到了解决方案:
densityplot(~gcsescore | factor(score), data=Chem97,
panel=function(x,...){
panel.densityplot(x,...)
panel.abline(v=quantile(x,.5), col.line="red")
})
Run Code Online (Sandbox Code Playgroud)