您好我在r中使用coefplot函数绘制出广义线性模型的系数。我想将95%CI线的颜色更改为与50%CI线不同。对于95%和50%CI行,颜色参数默认颜色相同。
coeff<-coefplot(model1,pointSize=5,color="black",fillColor="grey",lwdOuter = 1.2,lwdInner=2)
coeff + theme_bw() +
theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank()) +
theme (axis.title.y = element_text(size=16)) +
theme(axis.title.x = element_text(size=16)) +
scale_y_discrete(name="",labels=c("NDAA","GAP","SS","PS","LL")) +
theme (axis.text.x = element_text(size=16)) +
theme(axis.text.x = element_text(size=16)) +
scale_x_continuous(name="Regression Estimate") +
labs(title = "") +
coord_flip()
答案 0 :(得分:6)
您可以创建自己的系数图表,以满足您的需求而不会有太多麻烦。这是ggplot2
示例:
library(ggplot2)
# Create a model to plot
m1 = lm(mpg ~ wt + cyl + carb, data=mtcars)
coefs = as.data.frame(summary(m1)$coefficients[-1,1:2])
names(coefs)[2] = "se"
coefs$vars = rownames(coefs)
ggplot(coefs, aes(vars, Estimate)) +
geom_hline(yintercept=0, lty=2, lwd=1, colour="grey50") +
geom_errorbar(aes(ymin=Estimate - 1.96*se, ymax=Estimate + 1.96*se),
lwd=1, colour="red", width=0) +
geom_errorbar(aes(ymin=Estimate - se, ymax=Estimate + se),
lwd=2.5, colour="blue", width=0) +
geom_point(size=4, pch=21, fill="yellow") +
theme_bw()
答案 1 :(得分:1)
您无法在此轻松更改颜色。 不幸的是,这里的包不能访问设置颜色。
grid
包或gTable
更改凹凸颜色。这是肮脏的解决方案。它假设你知道如何在ggplot树对象(gpath)中导航答案 2 :(得分:0)
我遇到了同样的问题。
如果您更改单个coefplot
图层,则可以在ggplot2
内解决此问题。
coef <- coefplot(model = model1
, color = "blue"
) +
theme_bw()
coef$layers[[2]] <- geom_errorbarh(stat="identity", position = "identity", na.rm = FALSE
, color = "yellow"
, size = 1
, mapping = aes(xmin = LowOuter, xmax = HighOuter
, height = 0, linetype = Model
))
coef$layers[[3]] <- geom_errorbarh(stat="identity", position = "identity", na.rm = FALSE
, color = "red"
, size = 2
, mapping = aes(xmin = LowInner, xmax = HighInner
, height = 0, linetype = Model
))
coef