首页 > 解决方案 > 如何在 plot_models 函数中更改点颜色、位置和值大小

问题描述

Q1:plot_models 函数。是的,可以解决点大小,但是值大小和位置不起作用。value.size= 在这里不起作用。如何解决?Q2:见下图,点的颜色是自动设置的,有什么办法可以改变点的颜色,因为黄色对读者来说太糟糕了。

这是语法:

plot_models(myfit01, myfit03, myfit04, myfit05, myfit14, myfit19, myfit22,
transform="exp", legend.title = "Topics",axis.lim = c(0.1, 8), 
axis.labels = c("NBV", "BAS"),
m.labels = c("T01", "T03", "T04","T05", "T14", "T19","T22"),show.values = T, 
show.p = T, p.shape = TRUE, digits=4, 
p.threshold = c(0.05, 0.01, 0.001), 
vline.color = "#edd840",dot.size = 3, spacing=0.7, ci.lvl=0.95, grid=F)+
theme_bw()+theme( legend.title = element_text(color = "blue", size = 14),
legend.text = element_text(size = 12),axis.title.x = element_text(size = 14), 
axis.text.x = element_text(size=14), axis.text.y = element_text(size=16))+
ggtitle("szc")+
theme(plot.title = element_text(family="Georgia", colour="black", size=14))

通过 sjPlot

标签: rsjplot

解决方案


您使用“col =”选项和大小更改颜色,我猜您指的是文本的大小,没有选项,不幸的是您需要更改 geom_text 的默认值..见下文:

一些示例数据:

library(ggplot2)
library(sjPlot)

data(efc)
fit1 <- lm(barthtot ~ c160age + c12hour + c161sex + c172code, data = efc)
fit2 <- lm(neg_c_7 ~ c160age + c12hour + c161sex + c172code, data = efc)
fit3 <- lm(tot_sc_e ~ c160age + c12hour + c161sex + c172code, data = efc)

然后:

GeomText$default_aes$size
[1] 3.88

这是文本的默认大小,您可以向下减小大小。这是情节最初的样子:

plot_models(fit1,fit2,fit3, 
axis.labels = c("Carer's Age", "Hours of Care"),
m.labels = c("Barthel Index", "Negative Impact", "Services used"),
show.values = TRUE, show.p = TRUE,
p.shape = TRUE, digits=4, 
p.threshold = c(0.05, 0.01, 0.001), 
vline.color = "#edd840",dot.size = 3, spacing=0.7, ci.lvl=0.95, grid=F,
colors = c("orange","salmon","cadetblue"))

在此处输入图像描述

现在我们改变它们:

GeomText$default_aes$size <- 2.5
plot_models(fit1,fit2,fit3, 
axis.labels = c("Carer's Age", "Hours of Care"),
m.labels = c("Barthel Index", "Negative Impact", "Services used"),
show.values = TRUE, show.p = TRUE,
p.shape = TRUE, digits=4, 
p.threshold = c(0.05, 0.01, 0.001), 
vline.color = "#edd840",dot.size = 3, spacing=0.7, ci.lvl=0.95, grid=F,
colors = "social")

在此处输入图像描述

您可以选择一系列调色板:

show_sjplot_pals()

或者您可以指定自己的颜色,例如:

colors = c("grey","orange","red")

推荐阅读