我试图在两个具有相同预测变量的线性模型的回归量上的系数的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
Run Code Online (Sandbox Code Playgroud)
"y"列是模型的标签,reg是回归量,coef和se是您的想法.
我想绘图:
g <- qplot(reg, coef, facets=.~y, data = r.together) + coord_flip()
Run Code Online (Sandbox Code Playgroud)
但当我尝试显示情节时,我得到:
> print(g)
Error in names(df) <- output :
'names' attribute [2] must be the same length as the vector [1]
Run Code Online (Sandbox Code Playgroud)
有点奇怪的是
qplot(reg, coef, colour=y, data = r.together) + coord_flip()
Run Code Online (Sandbox Code Playgroud)
如你所料的情节.
我不知道为什么,但名字y似乎是问题所在.如果你改变它,那么它的工作原理
r.together <- read.table(textConnection("
reg coef se myfactor
(Intercept) 5.068608671 0.6990873 Labels
goodTRUE 0.310575129 0.5228815 Labels
indiaTRUE -1.196868662 0.5192330 Labels
moneyTRUE -0.586451273 0.6011257 Labels
maleTRUE -0.157618168 0.5332040 Labels
(Intercept) 4.225580743 0.6010509 Bonus
goodTRUE 1.272760149 0.4524954 Bonus
indiaTRUE -0.829588862 0.4492838 Bonus
moneyTRUE -0.003571476 0.5175601 Bonus
maleTRUE 0.977011737 0.4602726 Bonus
"),header=T)
qplot(reg, coef, data = r.together, facets= .~myfactor ) + coord_flip()
Run Code Online (Sandbox Code Playgroud)