在 coefplot 中手动排序系数

问题描述

我想手动对 coefplot 中的系数进行排序。之前的questions只实现了(减少)magnitude的排序,这不是我想要的。

考虑以下示例:

library(coefplot)
data(tips,package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker + sex * smoker,data = tips)
coefplot.glm(mod1)

如何在不依赖于它们的大小的情况下,在 sexMale:smokerYes 顶部和 daySatdayThudaySun(然后是其余部分)的情况下实现系数顺序?

>

预先感谢您为我指出解决方案。 :)

解决方法

因为 #include <iostream> #include <string> int main() { uint32_t * arr,K; std::string in; std::cout << "Array size -> "; std::cin >> in; K = std::stoi(in); arr = new uint32_t[K]; std::cout << "arr[0] -> "; std::cin >> in; arr[0] = std::stoi(in); std::cout << "arr[0] * 2 -> " << arr[0] * 2; delete [] arr; return 0; } 正在输出一个 coefplot.glm() 对象,所以您可以访问数据对象并重新调整 y 因子:

创建 ggplot 对象

ggplot

enter image description here

重新调整 y 因子

library(coefplot)
data(tips,package = "reshape2")
mod1 <- lm(tip ~ day + sex + smoker + sex * smoker,data = tips)
gg <- coefplot.glm(mod1)
gg

enter image description here