我想在箱线图中可视化一些数据。我有用 Python 编写的代码,但我想用 R 重写它。这是 Python 中的代码:fig, ax = plt.subplots()d = df.to_numpy()f = [d[m] for d, m in zip(d.T, ~np.isnan(d).T)]ax.boxplot(f)ax.set_ylim([0, 150])ax.set_ylabel('IRE binding activity (%)', fontsize=14)ax.set_xticklabels(['NF', 'F'])ax.tick_params(axis='x', labelsize=14, labelrotation=45)ax.tick_params(axis='y', labelsize=14)glue('fig1', fig, display=False)这是我在 R 中尝试过的:na_if(d, df)f <- [d[m] for d, m in zip(d.T, ~np.isnan(d).T)]boxplot(f)boxplot(NF ~ F, data = f, col = "lightgray", varwidth = TRUE, main = "IRE binding activity for non-failing (NF) and failing (F) hearts.", ylab = "IRE binding activity (%)",xlab = "['NF', 'F']")fivenum(f)我的数据代码包含一个 t 检验函数:labels <- list('non-failing heart (NF)', 'failing heart (F)')data <- list(c(99, 52), c(96, 40), c(100, 38), c(105, 18), c(NA_integer_, 11), c(NA_integer_, 5), c(NA_integer_, 42), c(NA_integer_, 55), c(NA_integer_, 53), c(NA_integer_, 39), c(NA_integer_, 42), c(NA_integer_, 50))df <- setNames(do.call(rbind.data.frame, lapply(data, function(d) data.frame(d[1], d[2]))), labels) df results <- t.test(df[['non-failing heart (NF)']], df[['failing heart (F)']])results results$statisticresults$estimateresults$p.value ceiling(results$p.value * 1000.0)/ 1000.0
1 回答
繁花如伊
TA贡献2012条经验 获得超12个赞
我已经成功地用 R 重写了代码,我想与您分享解决方案:
boxplot(df[1:2],
data=df,
main="box plot",
ylab="Degree Fahrenheit",
col="orange",
border="brown",
ylim = c(0, 120)
)
添加回答
举报
0/150
提交
取消