为什么 ylim 和 xlim 在成对绘图中不起作用?

huangapple go评论95阅读模式
英文:

Why are ylim and xlim not working in pairs plot?

问题

I've translated the code parts as requested:

  1. 我一直在尝试调整多个图的坐标轴,使用```pairs```,以使它们都在同一个轴上。这里是一个可重现的例子:
  2. 结构(列表)(LS_avg_RT_diff_L1 = c(80.6931818181818, 132.140625,
  3. 17.3957219251338, 17.7260619977038, 132.270508203281, 48.7419786096257,
  4. 61.5816849816849, 44.4324596774193, 80.8417471466198, 65.4357864357864,
  5. 83.2645687645688, 36.264116575592, 67.0728778467909, 60.1642857142856,
  6. -14.4822346891071, 45.9939516129032, 42.7380090497737, 90.2058823529412,
  7. 27.6024667931689, 93.5517494494738), LS_avg_RT_diff_L2 = c(77.5145135566187,
  8. 40.8939393939395, 29.6952853598016, 72.9280753968254, -14.1512868801005,
  9. 85.6644052464948, 30.2159709618876, -11.433465085639, 64.1141025641025,
  10. 74.4760374050264, 53.6344431687714, 43.5934426229509, -9.48846153846159,
  11. 36.4078947368421, 22.3389830508474, 37.0996168582376, 3.98615617564349,
  12. 101.859614968635, 15.8340548340548, 64.2138275124732), F_Avg_RT_incong_cong_diff = c(171.598614692351,
  13. 102.555176953458, 137.872214816226, 125.230948166877, 51.7965631337389,
  14. 134.295988295988, 120.740762463343, 100.648528099911, 106.099431818182,
  15. 105.072854715378, 70.708551526529, 123.551755014327, 96.0822281167109,
  16. 122.687703999003, 119.429894937918, 120.140225128698, 76.5200041540099,
  17. 111.617893755825, 213.413735177866, 143.796112730807), CS_Avg_RT_sw_stay_diff = c(96.0248439450687,
  18. 13.6687620889749, 43.9708908113163, 106.518604651163, 77.4642017245884,
  19. 31.8150793650793, -54.9493941553814, 43.6563866241286, 11.0111111111111,
  20. 18.3352925809822, 30.7129426129426, 21.9990338164251, -27.7946428571429,
  21. 28.8394863563403, 6.10227272727275, 20.1549806576402, 79.845259391771,
  22. 12.6738336713995, 4.97893772893769, 54.8049335863378)), 行名 = c(NA,
  23. 20L), 类别 = "数据框")
  24. 并且我的代码:
  25. 面板 <- function(x,y){
  26. points(x,y, col = "蓝色", pch = 21, bg = "蓝色")
  27. abline(lm(y~x), col="红色")}
  28. 我的文本面板 <- function(labels) {
  29. function(x, y, lbl, ...) {
  30. if (lbl %in% names(labels)) lbl <- labels[[lbl]]
  31. text(x, y, lbl, ...)}}
  32. 对(x = Corr_data_noppt[1:4],
  33. xlim = c(-100, 250),
  34. ylim = c(-100, 250),
  35. diag.panel = labels,
  36. text.panel = my.text.panel(c(LS_avg_RT_diff_L1="L1的RT切换成本",
  37. LS_avg_RT_diff_L2="L2的RT切换成本",
  38. F_Avg_RT_incong_cong_diff="Flanker RT成本",
  39. CS_Avg_RT_sw_stay_diff="颜色-形状RT成本")),
  40. lower.panel = panel,
  41. font.labels = 1,
  42. cex.labels = 1.2,
  43. upper.panel = NULL) #仅显示矩阵的下半部分

根据其他类似情况,xlimylim 可以作为参数添加到 pairs 中,但对我来说这并不起作用,我得到一个错误,说它们不被接受:

  1. Error in upper.panel(...) :
  2. unused arguments (xlim = c(-100, 250), ylim = c(-100, 250))

我尝试将它们分别添加到:

  1. panel <- function(x,y){
  2. points(x,y, col = "蓝色", pch = 21, bg = "蓝色")
  3. abline(lm(y~x), col="红色")
  4. xlim = c(-100, 250)
  5. ylim = c(-100, 250)}

但这完全没有改变任何东西。

有任何建议吗?

  1. <details>
  2. <summary>英文:</summary>
  3. I&#39;ve been trying to adjust the axes of multiple plots using ```pairs```, such that they are all on the same axis. Here&#39;s a reproducible example:

structure(list(LS_avg_RT_diff_L1 = c(80.6931818181818, 132.140625,
17.3957219251338, 17.7260619977038, 132.270508203281, 48.7419786096257,
61.5816849816849, 44.4324596774193, 80.8417471466198, 65.4357864357864,
83.2645687645688, 36.264116575592, 67.0728778467909, 60.1642857142856,
-14.4822346891071, 45.9939516129032, 42.7380090497737, 90.2058823529412,
27.6024667931689, 93.5517494494738), LS_avg_RT_diff_L2 = c(77.5145135566187,
40.8939393939395, 29.6952853598016, 72.9280753968254, -14.1512868801005,
85.6644052464948, 30.2159709618876, -11.433465085639, 64.1141025641025,
74.4760374050264, 53.6344431687714, 43.5934426229509, -9.48846153846159,
36.4078947368421, 22.3389830508474, 37.0996168582376, 3.98615617564349,
101.859614968635, 15.8340548340548, 64.2138275124732), F_Avg_RT_incong_cong_diff = c(171.598614692351,
102.555176953458, 137.872214816226, 125.230948166877, 51.7965631337389,
134.295988295988, 120.740762463343, 100.648528099911, 106.099431818182,
105.072854715378, 70.708551526529, 123.551755014327, 96.0822281167109,
122.687703999003, 119.429894937918, 120.140225128698, 76.5200041540099,
111.617893755825, 213.413735177866, 143.796112730807), CS_Avg_RT_sw_stay_diff = c(96.0248439450687,
13.6687620889749, 43.9708908113163, 106.518604651163, 77.4642017245884,
31.8150793650793, -54.9493941553814, 43.6563866241286, 11.0111111111111,
18.3352925809822, 30.7129426129426, 21.9990338164251, -27.7946428571429,
28.8394863563403, 6.10227272727275, 20.1549806576402, 79.845259391771,
12.6738336713995, 4.97893772893769, 54.8049335863378)), row.names = c(NA,
20L), class = "data.frame")

  1. And my code:

panel <- function(x,y){
points(x,y, col = "blue", pch = 21, bg = "blue")
abline(lm(y~x), col="red")}

my.text.panel <- function(labels) {
function(x, y, lbl, ...) {
if (lbl %in% names(labels)) lbl <- labels[[lbl]]
text(x, y, lbl, ...)}}

pairs(x = Corr_data_noppt[1:4],
xlim = c(-100, 250),
ylim = c(-100, 250),
diag.panel = labels,
text.panel = my.text.panel(c(LS_avg_RT_diff_L1="RT Switching costs for L1",
LS_avg_RT_diff_L2="RT Switching costs for L2",
F_Avg_RT_incong_cong_diff="Flanker RT costs",
CS_Avg_RT_sw_stay_diff="Colour-Shape RT costs")),
lower.panel = panel,
font.labels = 1,
cex.labels = 1.2,
upper.panel = NULL) #show only the low half of the matrix

  1. According to other cases on here, ```xlim``` and ```ylim``` can be added as arguments to ```pairs```, but that doesn&#39;t work for me and I get an error that they are not taken as such:

Error in upper.panel(...) :
unused arguments (xlim = c(-100, 250), ylim = c(-100, 250))

  1. I tried alternatively adding them onto:

panel <- function(x,y){
points(x,y, col = "blue", pch = 21, bg = "blue")
abline(lm(y~x), col="red")
xlim = c(-100, 250)
ylim = c(-100, 250)}

  1. But that changed absolutely nothing.
  2. Any suggestions?
  3. </details>
  4. # 答案1
  5. **得分**: 2

你需要通过使用省略号 (...) 结构为你的自定义面板函数允许额外的参数(例如 xlim):

  1. panel <- function(x, y, ...){
  2. points(x,y, col = "blue", pch = 21, bg = "blue")
  3. abline(lm(y~x), col="red")}
  1. <details>
  2. <summary>英文:</summary>
  3. You need to allow additional arguments (e. g. `xlim`) to your custom panel function by [using the dot-dot-dot (`...`) construct][1]:

panel <- function(x, y, ...){
points(x,y, col = "blue", pch = 21, bg = "blue")
abline(lm(y~x), col="red")}

  1. [1]: https://stackoverflow.com/questions/3057341/how-to-use-rs-ellipsis-feature-when-writing-your-own-function
  2. </details>

huangapple
  • 本文由 发表于 2023年5月14日 21:27:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定