[英]changing the legend of dotwhisker to custom values r
I have this sample of code in R, printing a regression model.我在 R 中有这个代码示例,打印回归 model。 I am trying to make the legend more readable than true/false.我试图让传说比真/假更具可读性。 How can input my own text?如何输入我自己的文字? such as Significant or nonsignificant?比如显着还是不显着?
library(nycflights13)
library(dplyr)
library(dotwhisker)
library(MASS)
flights <- nycflights13::flights
flights<- sample_n (flights, 500)
m1<- glm(formula = arr_delay ~ dep_time + origin+ air_time+ distance , data = flights)
#m1<- glm(formula = arr_delay ~ . , data = flights)
m1<- stepAIC(m1)
p<- dotwhisker::dwplot(m1)
p$layers[[1]]$mapping[5] <- aes(color = p.value < 0.05)
p$layers[[2]]$mapping[4] <- aes(color = p.value < 0.05)
p$labels$colour <- "Significant"
p$theme <- list()
z<- p +
geom_vline(xintercept=0, linetype="dashed")+
geom_segment(aes(x=conf.low,y=term,xend=conf.high,
yend=term,col=p.value<0.05)) +
geom_point(aes(x=estimate,y=term,col=p.value<0.05)) +
xlab("standardized coefficient") +
ylab("coefficient") +
ggtitle("coefficients in the model and significance")
print(z)
Thanks谢谢
You can use scale_color_hue
to change the labels.您可以使用scale_color_hue
更改标签。
library(ggplot2)
p +
geom_vline(xintercept=0, linetype="dashed")+
geom_segment(aes(x=conf.low,y=term,xend=conf.high,
yend=term,col=p.value<0.05)) +
geom_point(aes(x=estimate,y=term,col=p.value<0.05)) +
xlab("standardized coefficient") +
ylab("coefficient") +
ggtitle("coefficients in the model and significance") +
scale_color_hue(labels = c('Significant', 'nonsignificant'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.