ggplot中GLM的多个比较的输出

时间:2019-02-14 03:23:31

标签: r ggplot2 glm

我想在ggplot中可视化GLM的多个比较的输出。在我的示例中:

bottom: -1rem

现在我想在ggplot中将cld(glht(mI,linfct = mcp(BV =“ Tukey”)))的字母可视化,以得到输出:

OUTPUTPLOT

这可能吗?谢谢

1 个答案:

答案 0 :(得分:2)

尝试一下:

library(tidyverse)

res <- cld(glht(mI, linfct = mcp(BV = "Tukey")))

d2 <-
  res$mcletters$Letters %>%
  tibble(
    reg = names(.),
    lett = .
  ) %>%
  mutate(
    Feature = substr(reg, 1, 1),
    Temp = substr(reg, 3, 3) %>% as.integer()
  ) %>%
  left_join(d2) %>%
  mutate(lett_pos = if_else(Feature == 'C', Production - .5, Production + .5))

ggplot(d2, aes(Temp, Production, colour = Feature)) +
  geom_point() +
  stat_smooth(method = "glm", formula = y ~ x) +
  geom_text(aes(y = lett_pos, label = lett), color = 'black')

enter image description here