Changing the name of the terms in ggally::ggcoef

Given the following example

iris_fat <- iris %>% mutate(is_fat = factor(ifelse(Sepal.Width * Petal.Width > 6 ,"fat", "not_fat")))
reg <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + is_fat, data = iris_fat)

enter image description here

How can I change the name of the term is_fatnot_fat to something else.

1 answer

  • answered 2018-03-13 21:58 Punintended

    My bad on the earlier comment, didn't read it carefully.

    ggcoef creates a list, just like the other ggplot functions. The first element, data, is a dataframe in which term maps to the y-axis. If you're curious, try str(test_plot$data) or examine it in RStudio

    test_plot <- ggcoef(reg)
    test_plot$data$term <- c("(Intercept)", "is_fat", "Petal.Length", "Petal.Width", "Sepal.Width")