R - vioplot,如何读取我的数据框中的列?

时间:2022-12-03 15:21:29

Forgive the simplicity of my question, I am very, very new to R and have found that the guides I am reading are really not getting to the point about how to do something this simple (perhaps they are assuming I should know this already?).

原谅我问题的简单性,我对R非常非常新,并且发现我正在阅读的指南真的没有达到如何做这么简单的事情(也许他们假设我应该知道这个?) 。

Anyhow, I am trying to use vioplot to plot the distributions of data in three columns. One plot per column of my data file. The data file has already been read in with read.table.

无论如何,我试图用vioplot绘制三列数据的分布。我的数据文件每列一个图。已经使用read.table读入了数据文件。

Ignore the df[names(df)=="Fst_ceu_mkk"] parts here as I am aware that this doesn't work (I found it in a guide). Could anyone tell me what to use in their stead to read the data from the columns named? They are the 3rd, 4th and 5th columns in the file.

忽略df [names(df)==“Fst_ceu_mkk”]部分,因为我知道这不起作用(我在指南中找到了它)。任何人都可以告诉我用什么来代替名为列的数据来读取数据?它们是文件中的第3,第4和第5列。

library(vioplot)
x1 <- df[names(df)=="Fst_ceu_mkk"]
x2 <- df[names(df)=="Fst_ceu_yri"]
x3 <- df[names(df)=="Fst_mkk_yri"]
vioplot(x1, x2, x3, names=c("CEU/MKK", "CEU/YRI", "MKK/YRI"),
   col="gold")
title("Genome-Wide FST Distribution by Population Pair")

1 个解决方案

#1


1  

It depends on the names of the columns in your data frame, but a general solution might be:

它取决于数据框中列的名称,但一般解决方案可能是:

vioplot(df[,colnames(df)[3]], df[,colnames(df)[4]], df[,colnames(df)[5]])

#1


1  

It depends on the names of the columns in your data frame, but a general solution might be:

它取决于数据框中列的名称,但一般解决方案可能是:

vioplot(df[,colnames(df)[3]], df[,colnames(df)[4]], df[,colnames(df)[5]])