在 R 中可视化 Python 编写的 Boxplot 的问题

我想在箱线图中可视化一些数据。我有用 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


收到一只叮咚
浏览 68回答 1
1回答

繁花如伊

我已经成功地用 R 重写了代码,我想与您分享解决方案:boxplot(df[1:2],&nbsp; &nbsp; &nbsp; &nbsp; data=df,&nbsp; &nbsp; &nbsp; &nbsp; main="box plot",&nbsp; &nbsp; &nbsp; &nbsp; ylab="Degree Fahrenheit",&nbsp; &nbsp; &nbsp; &nbsp; col="orange",&nbsp; &nbsp; &nbsp; &nbsp; border="brown",&nbsp; &nbsp; &nbsp; &nbsp; ylim = c(0, 120))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python