我想在箱线图中可视化一些数据。我有用 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$statistic
results$estimate
results$p.value
ceiling(results$p.value * 1000.0)/ 1000.0
繁花如伊
相关分类