gpt4 book ai didi

r - 使用 plot_model() 更改线型和线条颜色

转载 作者:行者123 更新时间:2023-12-04 12:08:40 26 4
gpt4 key购买 nike

我正在尝试使用 plot_model() 创建预测值图函数来自 sjPlot .我希望我的预测线具有不同的线型和不同的颜色。

该函数包括一个 colors参数和设置 colorsbw会变linetype ,但设置 colors到灰度。这个问题很相似,但没有收到有用的答案:Colored ribbons and different linetypes in sjPlot plot_model()

例子:

不同 linetypes ,但不是 colors

data(iris)
toy_model <- lm( Sepal.Length ~ Sepal.Width + Species, data=iris)

my_plot <- plot_model(toy_model, type=("pred"),
terms=c("Sepal.Width","Species"),
colors="bw")


不同 colors ,但不是 linetypes
data(iris)
toy_model <- lm( Sepal.Length ~ Sepal.Width + Species, data=iris)

my_plot <- plot_model(toy_model, type=("pred"),
terms=c("Sepal.Width","Species"))


我怎样才能得到两个不同的 colors和不同 linetypes ?换句话说,我想要这样的东西

this

最佳答案

sjPlot在定制方面似乎相当严格,但有一些方法可以解决。您可以从 ggpredict 获取数据(来自 ggeffects 包)并在 ggplot 中像往常一样自定义绘图.

df <- ggpredict(toy_model, terms = c("Sepal.Width","Species"))
ggplot(df, aes(x, predicted)) +
geom_line(aes(linetype=group, color=group)) +
geom_ribbon(aes(ymin=conf.low, ymax=conf.high, fill=group), alpha=0.15) +
scale_linetype_manual(values = c("solid", "dashed", "dotted"))

example

关于r - 使用 plot_model() 更改线型和线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57536714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com