R 使用plot_model()更改线型和线颜色
我正在尝试使用R 使用plot_model()更改线型和线颜色,r,ggplot2,sjplot,R,Ggplot2,Sjplot,我正在尝试使用sjPlot中的plot\u model()函数创建预测值的绘图。我希望预测线具有不同的线型和颜色 该函数包括一个colors参数,将colors设置为bw将更改linetype,但将colors设置为灰度。这个问题类似,但没有得到任何有用的答案: 示例: 不同的线型,但不同的颜色 数据(iris) toy_model在定制方面似乎相当死板,但有一些方法可以解决。您可以从ggpredict(从ggeffectspackage)获取数据,并像往常一样在ggplot中自定义绘图 df
sjPlot
中的plot\u model()
函数创建预测值的绘图。我希望预测线具有不同的线型和颜色
该函数包括一个colors
参数,将colors
设置为bw
将更改linetype
,但将colors
设置为灰度。这个问题类似,但没有得到任何有用的答案:
示例:
不同的线型
,但不同的颜色
数据(iris)
toy_model在定制方面似乎相当死板,但有一些方法可以解决。您可以从ggpredict
(从ggeffects
package)获取数据,并像往常一样在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"))
dfplot\u model
允许ggplot2
功能调整绘图的特征。
您可以轻松更改颜色或线型
library(sjPlot)
library(ggplot2)
data(iris)
toy_model <- lm( Sepal.Length ~ Sepal.Width + Species, data=iris)
#Use aes to change color or linetype
plot_model(toy_model, type=("pred"),
terms=c("Sepal.Width","Species")) + aes(linetype=group, color=group)
#Change color
plot_model(toy_model, type=("pred"),
terms=c("Sepal.Width","Species"), colors = "Set2") + aes(linetype=group, color=group)
库(sjPlot)
图书馆(GG2)
数据(iris)
玩具模型谢谢,它解决了部分问题:使用此解决方案后,我的一条线变为虚线。1.我怎样才能让它变成虚线呢?2.如何使虚线成为另一条线,而不是自动变为虚线的那条线?