gpt4 book ai didi

r - 如何不成比例地分割 y 轴以更好地在图中显示数据

转载 作者:行者123 更新时间:2023-12-01 08:29:32 25 4
gpt4 key购买 nike

我有一个名为 final 的 data.frame,如下所示:

             labels        gvs order color       f3
1 Adygei -2.3321916 1 1 353.0184
2 Basque -0.8519079 2 1 368.1515
3 French -0.9298674 3 1 365.2545
4 Italian -2.8859587 4 1 354.4481
5 Orcadian -1.4996229 5 1 350.9650
6 Russian -1.5597359 6 1 358.9736
7 Sardinian -1.4494841 7 1 355.1171
8 Tuscan -2.4279528 8 1 362.4717
9 Bedouin -3.1717421 9 2 319.3706
10 Druze -0.5058627 10 2 346.2211
11 Mozabite -2.6491331 11 2 299.5014
12 Palestinian -0.7819299 12 2 330.4576
13 Balochi -1.4095947 13 3 327.1238
14 Brahui -1.2534511 14 3 331.0927
15 Burusho 1.7958170 15 3 335.0919
16 Hazara 2.2810477 16 3 325.2444
17 Kalash -0.9258497 17 3 337.7116
18 Makrani -0.9007551 18 3 321.5726
19 Pathan 2.5543214 19 3 326.1923
20 Sindhi 2.6614486 20 3 318.7025
21 Uygur -1.2207974 21 3 322.0286
22 Cambodian 2.3706977 22 4 310.8989
23 Dai -0.9441980 23 4 305.5687
24 Daur -1.0325107 24 4 309.0984
25 Han -0.7381369 25 4 309.1198
26 Hezhen -2.7590587 26 4 296.9128
27 Japanese -0.5644325 27 4 297.9313
28 Lahu -0.8449225 28 4 307.0776
29 Miao -0.7237586 29 4 303.6593
30 Mongola -0.9452944 30 4 302.1380
31 Naxi -0.1625003 31 4 311.8019
32 Oroqen -1.2035258 32 4 308.7219
33 She -2.7758460 33 4 302.1271
34 Tu -0.7703779 34 4 307.3750
35 Tujia -1.0265275 35 4 303.5923
36 Xibo -1.1163019 36 4 295.5764
37 Yakut -3.2102686 37 4 315.0111
38 Yi -0.9614190 38 4 296.8134
39 Colombian -1.9659984 39 5 311.3134
40 Karitiana -0.9195156 40 5 300.8539
41 Maya 2.1239768 41 5 333.8995
42 Pima -3.0895998 42 5 325.3484
43 Surui -0.9377928 43 5 313.8505
44 Melanesian -1.6961014 44 6 294.5214
45 Papuan -0.7037952 45 6 286.7389
46 BantuKenya -1.9311354 46 7 152.9971
47 BantuSouthAfrica -1.8515908 47 7 133.6722
48 BiakaPygmy -1.7657017 48 7 117.5555
49 Mandenka -0.5423822 49 7 152.8525
50 MbutiPygmy -1.6244801 50 7 114.1691
51 San -0.9049735 51 7 0.0000
52 Yoruba 2.0949378 52 7 154.4460

我正在使用以下代码来制作图表

jpeg("F3.SCZ.Jul_22.jpg", 700,700)
final$color <- as.factor(final$color)
levels(final$color) <- c("blue","yellow3","red","pink","purple","green","orange")
plot(final$gvs, final$f3, cex=2,pch = 21, bg = as.character(final$color), xaxt="n", xlab="Genetic Values", ylab="F3", main="SCZ")
dev.off()

看起来像:

enter image description here

我想将 y 轴 分割为 200,使 y 值范围从 0 到 200 只占据图表的 10%,而 200 到 400 则占据图表的 10% y 轴的 90%。这可能吗?

编辑:

以下是遇到问题的数据:

             labels        gvs order color         f3
1 Adygei -2.3321916 1 1 0.09862109
2 Basque -0.8519079 2 1 0.09942770
3 French -0.9298674 3 1 0.10357547
4 Italian -2.8859587 4 1 0.09960179
5 Orcadian -1.4996229 5 1 0.10244666
6 Russian -1.5597359 6 1 0.10097691
7 Sardinian -1.4494841 7 1 0.10189642
8 Tuscan -2.4279528 8 1 0.09794686
9 Bedouin -3.1717421 9 2 0.09272493
10 Druze -0.5058627 10 2 0.09682272
11 Mozabite -2.6491331 11 2 0.08563901
12 Palestinian -0.7819299 12 2 0.09331649
13 Balochi -1.4095947 13 3 0.09227273
14 Brahui -1.2534511 14 3 0.09328593
15 Burusho 1.7958170 15 3 0.09396032
16 Hazara 2.2810477 16 3 0.09342432
17 Kalash -0.9258497 17 3 0.09666599
18 Makrani -0.9007551 18 3 0.09222257
19 Pathan 2.5543214 19 3 0.09468376
20 Sindhi 2.6614486 20 3 0.09172395
21 Uygur -1.2207974 21 3 0.09140727
22 Cambodian 2.3706977 22 4 0.08655821
23 Dai -0.9441980 23 4 0.08739080
24 Daur -1.0325107 24 4 0.08656669
25 Han -0.7381369 25 4 0.08764395
26 Hezhen -2.7590587 26 4 0.08802065
27 Japanese -0.5644325 27 4 0.08810874
28 Lahu -0.8449225 28 4 0.08609791
29 Miao -0.7237586 29 4 0.08700414
30 Mongola -0.9452944 30 4 0.08921706
31 Naxi -0.1625003 31 4 0.08646436
32 Oroqen -1.2035258 32 4 0.08719536
33 She -2.7758460 33 4 0.08656100
34 Tu -0.7703779 34 4 0.08818588
35 Tujia -1.0265275 35 4 0.08737680
36 Xibo -1.1163019 36 4 0.08806230
37 Yakut -3.2102686 37 4 0.08965344
38 Yi -0.9614190 38 4 0.08593454
39 Colombian -1.9659984 39 5 0.09114697
40 Karitiana -0.9195156 40 5 0.09040477
41 Maya 2.1239768 41 5 0.09068139
42 Pima -3.0895998 42 5 0.09084750
43 Surui -0.9377928 43 5 0.08925535
44 Melanesian -1.6961014 44 6 0.08430903
45 Papuan -0.7037952 45 6 0.08272786
46 BantuKenya -1.9311354 46 7 0.04668356
47 BantuSouthAfrica -1.8515908 47 7 0.03914248
48 BiakaPygmy -1.7657017 48 7 0.03546243
49 Mandenka -0.5423822 49 7 0.04612336
50 MbutiPygmy -1.6244801 50 7 0.03098719
51 San -0.9049735 51 7 0.00000000
52 Yoruba 2.0949378 52 7 0.04561542

最佳答案

你可以这样做:

my_color <- as.factor(final$color)
levels(my_color) <- c("blue","yellow3","red","pink","purple","green","orange")

par(mfrow = c(1,2))

# original plot
pos <- seq(min(final$f3), max(final$f3), by = 25) ## y-axis tick marks position.
plot(final$gvs, final$f3, cex=2, pch=21, bg = as.character(my_color),
xaxt="n", yaxt="n", xlab="Genetic Values", ylab="F3", main="SCZ")
axis(2, at = pos, labels = pos) ## add y-axis

# new plot
threshold <- 260 ## cut off threshold
## some rescaling
## if f3 < threshold, we take new_f3 <- 0.1 * f3
## if f3 > threshold, we take new_f3 <- f3 - 0.9 * threshold
new_f3 <- ifelse(final$f3 < threshold, 0.1 * final$f3, final$f3 - threshold * 0.9)
## we apply the same transform to `pos` to get `new_pos`
new_pos <- ifelse(pos < threshold, 0.1 * pos, pos - threshold * 0.9)

plot(final$gvs, new_f3, cex=2, pch=21, bg = as.character(my_color),
xaxt="n", yaxt="n", xlab="Genetic Values", ylab="F3", main="SCZ")
abline(h = threshold * 0.1, lty = 3) # threshold line
axis(2, at = new_pos, labels = pos)

enter image description here

关于r - 如何不成比例地分割 y 轴以更好地在图中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38535168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com