r - How to change the yaxis labels on plot model using sjplots package in R
问题描述
I applied linear regression(lm) model for my dataset. I got the expected results(as values) but the output holds the label name in all categories. Dataset seems: (Just a sample data for reference)
DARM Val hba_diff
Category1 23 2.5
Category2 54 3.8
Category3 56 5.2
Category4 89 6.1
Results after applying the below lm model :
lm(formula = hba_diff ~ DARM, data = DARM_data)
Output
Predictors Estimates CI p
(Intercept) 0.00 -0.10 – 0.10 0.957
DARM [Category1] 0.23 -0.30 – 0.75 0.398
DARM [Category2] 0.06 -0.25 – 0.37 0.719
DARM [Category3] 1.00 -2.18 – 4.17 0.538
DARM [Category4] -0.84 -2.67 – 1.00 0.372
I need to remove the 'DARM' in all rows of the output. Kindly suggest a code to remove the 'DARM' term in output set.
Expected output:
Predictors Estimates CI p
(Intercept) 0.00 -0.10 – 0.10 0.957
Category1 0.23 -0.30 – 0.75 0.398
Category2 0.06 -0.25 – 0.37 0.719
Category3 1.00 -2.18 – 4.17 0.538
Category4 -0.84 -2.67 – 1.00 0.372
解决方案
Please include the full code in the future. Not sure how you get the table, I guess you are using tab_model
function in sjplot
, so the easiest way is to provide the names, for example:
library(sjPlot)
df = data.frame(hba_diff=runif(50),
DARM = sample(c("Category1","Category2","Category3"),50,replace=TRUE))
fit = lm(hba_diff ~ DARM, data = df)
tab_model(fit,pred.labels = c("Intercept","Category2","Category3"))
To plot, do something likewise with ggplot2 (the plot is coord flipped so it is x axis):
library(ggplot2)
plot_model(fit) + scale_x_discrete(labels=c("Category2","Category3"))
推荐阅读
- php - 将 JSON 对象转换为 PHP 数组时出现问题
- puppeteer - Pupeteer:如何在 Linux 上指定 Chromium 路径
- python - 有没有办法搜索匹配关键字而不是全名的文本文件?
- firebase - 用于聊天应用的 Firebase 实时数据库或 Firestore?
- laravel - Laravel MorphMany 关系 - 我错过了什么?
- java - 我正在尝试从 Firebase 数据库中访问特定键的值。我想更新这些值并更新它
- linux - 为什么 wget 抛出 ERROR 403: Forbidden 错误?
- r - 如果在 if 语句中存在反应性数据框,请检查 R
- google-cloud-platform - 在 GCP Deployment Manager 配置中使用 Stackdriver 资源组的 ID
- javascript - 我无法取回我的数据,Post 功能工作正常,经过邮递员测试