r - 如何在 R 中使用 ggPredict 更改图形的颜色?情节(b,颜色=“bw”)?
问题描述
我做了这个模型:
lm1 <- lm(respiration.rate.calf~length+abs_pres,data=data)
并尝试将其可视化ggPredict
:
b<-ggPredict(lm1, se=TRUE)+labs(x="Calf length (m)", y="Calf respiration rate (breaths/min)")
plot(b)
但是,我得到的图表是红色和绿色的,但我必须以黑白打印图表。有谁知道如何更改线型(例如,一种实线和一种虚线)或颜色(一种亮和一种暗)ggPredict
?
我现在已经尝试了 3 个小时,我尝试的最后一件事是这样,但它不起作用:
plot(b, colors="bw")
解决方案
您可以使用ggplot()
功能并根据需要更改颜色
library(ggeffects)
library(ggplot2)
data(efc)
fit <- lm(barthtot ~ c12hour + bs(neg_c_7) * c161sex + e42dep, data = efc)
ggpredict(fit, terms = "c12hour")
mydf <- ggpredict(fit, se=TRUE)
mydf <- ggpredict(fit, terms = c("neg_c_7", "c161sex", "e42dep"))
ggplot(mydf, aes(x = x, y = predicted, colour = group)) +
geom_line() +
geom_ribbon( aes(ymin = conf.low, ymax = conf.high, fill = group, color = NULL), alpha = .15) +
facet_wrap(~facet) +
theme_bw() +
scale_color_manual(values=c('#999999','#E69F00'))+
scale_fill_manual(values=c("blue", "green"), name="fill")
推荐阅读
- php - Woocommerce 分页仅适用于商店主页
- r - R Shiny 在每一步将日志写入 ui
- docker - Kubernetes 暴露多个 pod
- asp.net - 我无法将外键保存到一对多表 asp.net 但可以插入数据 asp.net mvc 5
- c++ - 使用私有派生类的构造函数初始化基类的数据成员
- c++ - 示例中重载的 new 运算符如何在不传递要分配的内存大小的情况下工作?
- vmware-clarity - 如何在 Clarity Datagrid 列的默认过滤器中添加标签名称
- android - 需要更新我的 apk 不是从谷歌播放
- ruby-on-rails - Rails 5.2.1:文件输入被文本输入替换 - ActiveAdmin 嵌套属性表单
- javascript - 动画不适用于 Google Charts 中堆积条形图中的第三条(可视化)