尝试在 ggplot2 中创建多面图时出错
我正在尝试在 ggplot2 中绘制回归量系数的多面图 具有相同预测变量的两个线性模型。我构建的数据框是这样的:
r.together>
reg coef se y
1 (Intercept) 5.068608671 0.6990873 Labels
2 goodTRUE 0.310575129 0.5228815 Labels
3 indiaTRUE -1.196868662 0.5192330 Labels
4 moneyTRUE -0.586451273 0.6011257 Labels
5 maleTRUE -0.157618168 0.5332040 Labels
6 (Intercept) 4.225580743 0.6010509 Bonus
7 goodTRUE 1.272760149 0.4524954 Bonus
8 indiaTRUE -0.829588862 0.4492838 Bonus
9 moneyTRUE -0.003571476 0.5175601 Bonus
10 maleTRUE 0.977011737 0.4602726 Bonus
“y”列是模型的标签,reg是回归量,coef和se是你所想的。
我想绘制:
g <- qplot(reg, coef, facets=.~y, data = r.together) + coord_flip()
但是当我尝试显示该图时,我得到:
> print(g)
Error in names(df) <- output :
'names' attribute [2] must be the same length as the vector [1]
奇怪的是,该
qplot(reg, coef, colour=y, data = r.together) + coord_flip()
图正如您所期望的那样。
I am trying to make a faceted plot in ggplot2 of the coefficients on the regressors from
two linear models with the same predictors. The data frame I constructed is this:
r.together>
reg coef se y
1 (Intercept) 5.068608671 0.6990873 Labels
2 goodTRUE 0.310575129 0.5228815 Labels
3 indiaTRUE -1.196868662 0.5192330 Labels
4 moneyTRUE -0.586451273 0.6011257 Labels
5 maleTRUE -0.157618168 0.5332040 Labels
6 (Intercept) 4.225580743 0.6010509 Bonus
7 goodTRUE 1.272760149 0.4524954 Bonus
8 indiaTRUE -0.829588862 0.4492838 Bonus
9 moneyTRUE -0.003571476 0.5175601 Bonus
10 maleTRUE 0.977011737 0.4602726 Bonus
The "y" column is a label for the model, reg are the regressors and coef and se are what you would think.
I want to plot:
g <- qplot(reg, coef, facets=.~y, data = r.together) + coord_flip()
But when I try to display the plot, I get:
> print(g)
Error in names(df) <- output :
'names' attribute [2] must be the same length as the vector [1]
What's strange is that
qplot(reg, coef, colour=y, data = r.together) + coord_flip()
plots as you would expect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么,但名称
y
似乎是问题所在。如果你改变它,那么它就有效I don't know why, but the name
y
seems to be the problem. If you change it, then it works可能是你的保留字吗?
yy 似乎有效
Could be y a reserved word?
yy seems to work