简体   繁体   English

R中散点图矩阵的标签

[英]Labels for Scatterplot Matrix in R

I am new to R, so please consider this when investigating my presumably unelegant attempts to problem-solving. 我是R的新手,因此在调查我大概单调的解决问题的尝试时,请考虑这一点。

The data which I use come from a behavioral psychological study. 我使用的数据来自行为心理学研究。 I have a data frame, containing 6 different parameters (called mu, sigma, tau, v, a, Ter) from 3 different behavioral tasks each. 我有一个数据框,其中包含来自3个不同行为任务的6个不同参数(称为mu,sigma,tau,v,a,Ter)。 Additionally, there are 2 stimulus types, face and house pictures. 此外,还有2种刺激类型:面部和房屋照片。 colnames(plot_data) yields the following: colnames(plot_data)产生以下结果:

 [1] "subject"                      "v.DelayedNMatchingFaces"     
 [3] "a.DelayedNMatchingFaces"      "Ter.DelayedNMatchingFaces"   
 [5] "mu.DelayedNMatchingFaces"     "sigma.DelayedNMatchingFaces" 
 [7] "tau.DelayedNMatchingFaces"    "v.DelayedNMatchingHouses"    
 [9] "a.DelayedNMatchingHouses"     "Ter.DelayedNMatchingHouses"  
[11] "mu.DelayedNMatchingHouses"    "sigma.DelayedNMatchingHouses"
[13] "tau.DelayedNMatchingHouses"   "v.MorphFaces"                
[15] "a.MorphFaces"                 "Ter.MorphFaces"              
[17] "mu.MorphFaces"                "sigma.MorphFaces"            
[19] "tau.MorphFaces"               "v.MorphHouses"               
[21] "a.MorphHouses"                "Ter.MorphHouses"             
[23] "mu.MorphHouses"               "sigma.MorphHouses"           
[25] "tau.MorphHouses"              "v.verificFaces"              
[27] "a.verificFaces"               "Ter.verificFaces"            
[29] "mu.verificFaces"              "sigma.verificFaces"          
[31] "tau.verificFaces"             "v.verificHouses"             
[33] "a.verificHouses"              "Ter.verificHouses"           
[35] "mu.verificHouses"             "sigma.verificHouses"         
[37] "tau.verificHouses"

Now, I need to do bivaraite scatterplots that contain one single parameter, but of each task, so I want to do a 3x3 scatterplot matrix (eg: a.DelayedNMatchingFaces , a.MorphFaces , a.verificFaces ). 现在,我需要执行包含一个参数但只针对每个任务的Bivaraite散点图,因此我想做一个3x3散点图矩阵(例如: a.DelayedNMatchingFacesa.MorphFacesa.verificFaces )。 This matrix will be saved to a png that is named according to the parameter and the stimulus type (so for example "a_H.png" if it's the parameter a for house-stimuli). 该矩阵将保存为根据参数和刺激类型命名的png(因此,例如“ a_H.png”,如果它是用于房屋刺激的参数a)。 I have built a for-loop that goes through the columns and builds scatterplot a matrix of the variable from column i , column i+12 and column i+24 , because each parameter appears every 12th step in the header row. 我建立了一个遍历各列的for循环,并建立了散点图,构成了i列, i+12列和i+24列的变量矩阵,因为每个参数在标题行的第12步出现。 The loop looks as follows: 循环如下所示:

for (col_ix in 2:13) {

  i <- col_ix + 12
  j <- col_ix + 24

  param_col <- colnames(plot_data)[col_ix]
  param <- strsplit(param_col,"[.]")[[1]][1] 

  if (grepl("Faces", colnames(plot_data)[col_ix]) == TRUE) {
    stim_col <- "F" 
    }
  else {
    stim_col <- "H" 
    }

  png(paste(param, stim_col, ".png", sep="_"))
  scatterplotMatrix(~ plot_data[ ,col_ix] + plot_data[ ,i] + plot_data[ ,j] , span=0.7, data= plot_data)
  dev.off()

}

This seems to work, although I acknowledge that there must be a thousand ways to do it more efficiently, but hey, it's my first R loop, actually. 这似乎可行,尽管我承认必须有上千种方法才能更有效地执行此操作,但是,实际上,这是我的第一个R循环。 The problem is: When I save the scatterplot matrix as png file, the plots that are visible in the pngs are labeled according to the data source that is indicated in the formula, so in this case, it would be plot_data[col_ix] , plot_data[i] and plot_data[j] (see below). 问题是:当我将散点图矩阵另存为png文件时,根据公式中指示的数据源来标记png中可见的图,因此在这种情况下,它将是plot_data[col_ix]plot_data[i]plot_data[j] (见下文)。 The plots are supposed, however, to be labeled according to the column names, so that when you look at them, you can see which variable is displayed and plotted with which. 但是,应该假定这些图是根据列名进行标记的,因此,当您查看它们时,可以看到显示了哪个变量并使用哪个变量进行了绘制。 There is an argument that is called var.label s, I saw that already, but I just can't figure out how to have it name every plot, because the indices col_ix , i and j are running numbers and cannot all three be listed in the var.labels argument. 有一个名为var.label的参数,我已经知道了,但是我只是想不出如何命名每个图,因为索引col_ixij是运行数字,不能列出所有三个在var.labels参数中。

Can anyone help? 有人可以帮忙吗? Suggestions are greatly appreciated (also, by the way, if they contain advice not directly linked to the variable labels). 建议是非常值得赞赏的(顺便说一句,如果它们包含未直接链接到变量标签的建议)。 I apologize if my explanations were unprofessional or lacked the correct use of specific terms; 如果我的解释不专业或缺少正确使用特定术语的行为,我深表歉意。 hopefully everything was understandable. 希望一切都是可以理解的。 If there is more information required, please tell me, then I will add it. 如果需要更多信息,请告诉我,然后我会添加。

Much thanks to you all. 非常感谢大家。

you could just use the names associated with ij and col_ix as follows: 您可以仅使用与ij和col_ix关联的名称,如下所示:

plot_data[ , names(plot_data)[col_ix]] + plot_data[ ,names(plot_data)[i]] 
  + plot_data[, names(plot_data)[j]]

This may not immediately result in your desired outcome, but you can use the same method to get the names for var.labels: 这可能不会立即产生您想要的结果,但是您可以使用相同的方法来获取var.labels的名称:

var.labels= c(names(plot_data)[i], names(plot_data)[j])

or whatever the exact syntax is. 或确切的语法是什么。 I don't have this package installed, but this should get you pretty close. 我没有安装此软件包,但这应该可以使您更加接近。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM