我将感谢任何帮助在翻转轴如图所示.我尝试使用plot_model
在plot_model
(sjplot)但没有任何成功.我尝试coord_flip()
/ coord_flitp = TRUE但没有任何成功.
library(sjmisc)
library(sjPlot)
data(efc)
efc <- to_factor(efc, c161sex, e42dep, c172code)
m <- lm(neg_c_7 ~ pos_v_4 + c12hour + e42dep + c172code, data = efc)
# create plot-object
p <- plot_model(m)
# change theme
p + theme_sjplot()
library(lme4) # linear mixed-effects models
library(lmerTest) # test for linear mixed-effects models
library(gtsummary)
library(sjPlot)
library(ggplot2)
m1 <- lmer(distance ~ as.factor(year) + (1 | id), data = trajectories)
summary(m1)
p <- plot_model(m1)
p+coord_cartesian()
m2 <- lmer(distance ~ as.factor(year)+sex + (1 | id), data = trajectories)
summary(m2)
p2 <- plot_model(m2, rm.terms = c("sex [M]"))
p2+coord_cartesian()
p3 <- plot_models(m1,m2, rm.terms = c("sex [M]"),
axis.labels = c("2010","2009","2008","20007","2006", "2005","2004","2003","2002"))
p3+coord_cartesian()
p4 <- plot_models(m1,m2, rm.terms = c("sex [M]"),
axis.labels = c("2002","2003","2004","2005","2006", "2007","2008","2009","2010"))
p4+coord_cartesian()
下面是p3
输出
这是p4输出
这里是虚拟数据
> dput(trajectories)
structure(list(id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L), year = c(2001L, 2002L, 2003L, 2004L,
2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L, 2003L,
2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L,
2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L,
2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L,
2010L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2004L,
2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L, 2003L,
2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L,
2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L,
2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L,
2010L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L,
2009L, 2010L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L, 2007L,
2008L, 2009L, 2010L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
2007L, 2008L, 2009L, 2010L, 2001L, 2002L, 2003L, 2004L, 2005L,
2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L, 2003L, 2004L,
2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L, 2003L,
2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2001L, 2002L,
2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L), distance = c(15,
20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24, 21, 20, 21.5, 23,
21, 21.5, 24, 25.5, 20.5, 24, 21, 20, 21.5, 23, 21, 21.5, 24,
25.5, 20.5, 24, 21, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24,
21, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24, 21, 20, 21.5,
23, 21, 21.5, 21, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24,
23, 21, 21.5, 24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5,
24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5,
24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24, 15, 20, 21.5,
23, 21, 21.5, 24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5,
24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5,
24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24, 15, 20, 21.5,
23, 21, 21.5, 24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5,
24, 25.5, 20.5, 24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5,
24, 15, 20, 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24), age = c(8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 15L, 16L, 17L, 18L, 19L, 20L, 21L,
22L, 23L, 24L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 9L, 10L, 11L, 12L,
13L, 14L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 28L, 40L, 41L, 42L, 43L, 44L, 45L,
46L, 47L, 48L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 28L, 29L, 30L,
31L, 32L, 33L, 34L, 35L, 36L, 37L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L,
37L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 28L, 29L,
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 35L, 36L, 37L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L,
36L, 37L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L),
Quintile = structure(c(5L, 2L, 3L, 3L, 2L, 2L, 4L, 2L, 5L,
5L, 1L, 4L, 2L, 5L, 4L, 3L, 3L, 4L, 3L, 3L, 1L, 3L, 1L, 2L,
1L, 5L, 2L, 4L, 1L, 4L, 3L, 2L, 5L, 3L, 4L, 4L, 3L, 1L, 4L,
3L, 4L, 1L, 4L, 4L, 5L, 1L, 5L, 2L, 2L, 2L, 3L, 5L, 3L, 3L,
4L, 1L, 3L, 1L, 1L, 5L, 2L, 4L, 1L, 3L, 2L, 4L, 1L, 3L, 4L,
5L, 3L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 3L, 5L, 5L, 2L, 5L, 2L,
2L, 3L, 1L, 2L, 3L, 5L, 5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2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L), levels = c("F", "M"), class = "factor"), yr_qun = structure(c(6L,
8L, 14L, 18L, 21L, 26L, 32L, 35L, 43L, 48L, 2L, 10L, 13L,
20L, 23L, 27L, 31L, 37L, 41L, 46L, 2L, 9L, 1L, 1L, 1L, 1L,
30L, 37L, 39L, 47L, 4L, 8L, 16L, 18L, 23L, 28L, 31L, 34L,
42L, 46L, 5L, 7L, 15L, 19L, 24L, 25L, 33L, 35L, 40L, 45L,
4L, 11L, 14L, 18L, 23L, 25L, 4L, 7L, 12L, 20L, 21L, 28L,
29L, 36L, 40L, 47L, 17L, 22L, 28L, 33L, 36L, 41L, 44L, 3L,
8L, 14L, 17L, 21L, 27L, 33L, 38L, 40L, 48L, 3L, 8L, 14L,
17L, 21L, 27L, 33L, 38L, 40L, 48L, 3L, 8L, 14L, 17L, 1L,
1L, 1L, 38L, 40L, 1L, 1L, 1L, 14L, 17L, 21L, 27L, 33L, 38L,
40L, 48L, 1L, 1L, 14L, 17L, 21L, 27L, 33L, 38L, 40L, 48L,
1L, 1L, 14L, 17L, 21L, 27L, 33L, 38L, 40L, 48L, 1L, 1L, 14L,
17L, 21L, 27L, 33L, 38L, 40L, 48L, 1L, 1L, 14L, 17L, 21L,
27L, 33L, 38L, 40L, 48L, 1L, 1L, 14L, 17L, 21L, 27L, 33L,
38L, 40L, 48L, 1L, 1L, 14L, 17L, 21L, 27L, 33L, 38L, 40L,
48L, 1L, 1L, 14L, 17L, 21L, 27L, 33L, 38L, 40L, 48L), levels = c("",
"2001_Q1", "2001_Q2", "2001_Q3", "2001_Q4", "2001_Q5", "2002_Q1",
"2002_Q2", "2002_Q3", "2002_Q4", "2002_Q5", "2003_Q1", "2003_Q2",
"2003_Q3", "2003_Q4", "2003_Q5", "2004_Q1", "2004_Q3", "2004_Q4",
"2004_Q5", "2005_Q2", "2005_Q3", "2005_Q4", "2005_Q5", "2006_Q1",
"2006_Q2", "2006_Q3", "2006_Q4", "2007_Q1", "2007_Q2", "2007_Q3",
"2007_Q4", "2007_Q5", "2008_Q1", "2008_Q2", "2008_Q3", "2008_Q4",
"2008_Q5", "2009_Q1", "2009_Q2", "2009_Q3", "2009_Q4", "2009_Q5",
"2010_Q1", "2010_Q2", "2010_Q3", "2010_Q4", "2010_Q5"), class = "factor")), class = "data.frame", row.names = c(NA,
-183L))
1条答案
按热度按时间ergxz8rk1#
为了使用
plot_models()
重新排列翻转的x轴上的值,您可以以不同的顺序“传入”数据,例如。创建于2023-04-24带有reprex v2.0.2