为什么双轴曲线会产生耀斑?

时间:2017-12-17 02:13:58

标签: r plot

我试图使用R基础图形在两个轴图上绘制对一组变量的三个响应。类似的数字很好,但是对于我的一些数据集,曲线向x的范围的较高端展开。我没有重复的y值(曲线交叉的地方除外)。

为什么曲线会像这样闪耀?这是脚本或数据的问题吗?

情节,脚本和数据如下。

enter image description here

structure(list(x = c(10000L, 9900L, 9800L, 9700L, 9600L, 9500L, 
9400L, 9300L, 9200L, 9100L, 9000L, 8900L, 8800L, 8700L, 8600L, 
8500L, 8400L, 8300L, 8200L, 8100L, 8000L, 7900L, 7800L, 7700L, 
7600L, 7500L, 7400L, 7300L, 7200L, 7100L, 7000L, 6900L, 6800L, 
6700L, 6600L, 6500L, 6400L, 6300L, 6200L, 6100L, 6000L, 5900L, 
5800L, 5700L, 5600L, 5500L, 5400L, 5300L, 5200L, 5100L, 5000L, 
4900L, 4800L, 4700L, 4600L, 4500L, 4400L, 4300L, 4200L, 4100L, 
4000L, 3900L, 3800L, 3700L, 3600L, 3500L, 3400L, 3300L, 3200L, 
3100L, 3000L, 2900L, 2800L, 2700L, 2600L, 2500L, 2400L, 2300L, 
2200L, 2100L, 2000L, 1900L, 1800L, 1700L, 1600L, 1500L, 1400L, 
1300L, 1200L, 1100L, 1000L, 900L, 800L, 700L, 600L, 500L, 400L, 
300L, 200L, 100L, 100L, 200L, 300L, 400L, 500L, 600L, 700L, 800L, 
900L, 1000L, 1100L, 1200L, 1300L, 1400L, 1500L, 1600L, 1700L, 
1800L, 1900L, 2000L, 2100L, 2200L, 2300L, 2400L, 2500L, 2600L, 
2700L, 2800L, 2900L, 3000L, 3100L, 3200L, 3300L, 3400L, 3500L, 
3600L, 3700L, 3800L, 3900L, 4000L, 4100L, 4200L, 4300L, 4400L, 
4500L, 4600L, 4700L, 4800L, 4900L, 5000L, 10000L, 5100L, 9900L, 
9800L, 5200L, 9700L, 9600L, 5300L, 9500L, 9400L, 5400L, 9300L, 
5500L, 9200L, 9100L, 5600L, 9000L, 8900L, 5700L, 8800L, 5800L, 
8700L, 8600L, 5900L, 8500L, 6000L, 8400L, 8300L, 6100L, 8200L, 
6200L, 8100L, 6300L, 8000L, 7900L, 6400L, 7800L, 6500L, 7700L, 
6600L, 7600L, 6700L, 7500L, 6800L, 7400L, 6900L, 7300L, 7200L, 
7000L, 7100L, 100L, 200L, 300L, 400L, 500L, 600L, 700L, 800L, 
900L, 1000L, 1100L, 1200L, 1300L, 1400L, 1500L, 1600L, 1700L, 
1800L, 1900L, 2000L, 2100L, 2200L, 2300L, 2400L, 2500L, 2600L, 
2700L, 2800L, 2900L, 3000L, 3100L, 3200L, 3300L, 3400L, 3500L, 
3600L, 3700L, 3800L, 3900L, 4000L, 4100L, 4200L, 4300L, 4400L, 
4500L, 4600L, 4700L, 4800L, 4900L, 5000L, 5100L, 5200L, 5300L, 
5400L, 5500L, 5600L, 5700L, 5800L, 5900L, 6000L, 6100L, 6200L, 
6300L, 6400L, 6500L, 6600L, 6700L, 6800L, 6900L, 7000L, 10000L, 
7100L, 9900L, 9800L, 7200L, 9700L, 9600L, 7300L, 9500L, 7400L, 
9400L, 9300L, 7500L, 9200L, 7600L, 9100L, 9000L, 7700L, 8900L, 
7800L, 8800L, 7900L, 8700L, 8000L, 8600L, 8500L, 8100L, 8400L, 
8200L, 8300L), type = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L), y = c(7.604990636, 7.634529899, 7.664473356, 7.694830693, 
7.725611926, 7.756827424, 7.788487919, 7.820604527, 7.853188762, 
7.886252558, 7.91980829, 7.953868789, 7.988447373, 8.023557864, 
8.059214616, 8.095432545, 8.132227148, 8.169614547, 8.207611511, 
8.246235491, 8.285504668, 8.325437972, 8.366055146, 8.407376777, 
8.449424343, 8.492220279, 8.535788011, 8.58015203, 8.625337954, 
8.671372589, 8.718284006, 8.766101622, 8.814856278, 8.864580342, 
8.915307795, 8.967074346, 9.019917545, 9.073876908, 9.128994056, 
9.185312857, 9.242879595, 9.301743136, 9.361955126, 9.423570198, 
9.486646202, 9.551244447, 9.617429991, 9.685271926, 9.754843729, 
9.82622361, 9.899494936, 9.974746669, 10.05207387, 10.13157825, 
10.21336878, 10.29756243, 10.38428486, 10.47367136, 10.56586778, 
10.66103169, 10.75933353, 10.86095814, 10.96610628, 11.07499652, 
11.18786732, 11.30497947, 11.42661888, 11.55309983, 11.68476874, 
11.82200857, 11.96524403, 12.11494766, 12.27164714, 12.43593391, 
12.60847363, 12.79001873, 12.98142375, 13.18366417, 13.39785966, 
13.62530309, 13.86749717, 14.12620104, 14.40349036, 14.70183569, 
15.02420631, 15.37420985, 15.75628341, 16.17596061, 16.640253, 
17.15820968, 17.74176323, 18.40705516, 19.17660303, 20.08303176, 
21.1759258, 22.53549558, 24.30301095, 26.76001417, 30.5911217, 
38.2602731, 0.9157103, 1.56212355, 2.123827033, 2.6302968, 3.09459412, 
3.524180883, 3.923954743, 4.297431925, 4.647300689, 4.97571289, 
5.284451509, 5.575033383, 5.848775385, 6.106839129, 6.350262087, 
6.579980081, 6.796843912, 7.001632006, 7.195060226, 7.37778968, 
7.55043301, 7.713559573, 7.867699774, 8.013348721, 8.150969376, 
8.280995281, 8.40383293, 8.519863911, 8.629446762, 8.732918673, 
8.83059699, 8.922780613, 9.009751242, 9.091774529, 9.169101123, 
9.24196765, 9.310597605, 9.375202171, 9.435980987, 9.49312286, 
9.54680642, 9.597200743, 9.644465905, 9.688753532, 9.730207284, 
9.76896333, 9.805150774, 9.838892063, 9.870303367, 9.899494936, 
9.924515311, 9.926571435, 9.936941275, 9.949160166, 9.951632254, 
9.961161098, 9.972932717, 9.9747718, 9.984463178, 9.995740128, 
9.996079778, 10.00675067, 10.01564144, 10.01748137, 10.02791817, 
10.03353785, 10.03804643, 10.04785085, 10.04984608, 10.05731547, 
10.06463944, 10.06642361, 10.07515787, 10.0779877, 10.08350004, 
10.08995725, 10.09143115, 10.09893132, 10.10061128, 10.10597983, 
10.11000999, 10.11255499, 10.11821068, 10.11863413, 10.12419357, 
10.12526797, 10.12920852, 10.13123388, 10.13365308, 10.13615802, 
10.13750012, 10.14008767, 10.14072129, 10.1430679, 10.14328691, 
10.14514173, 10.14516591, 10.14632576, 10.14635019, 10.14673241, 
0.000103, 0.000885, 0.003126667, 0.007655075, 0.0153247, 0.027017, 
0.043628, 0.066064, 0.095235878, 0.13205312, 0.177417082, 0.232213667, 
0.297304992, 0.37352035, 0.461646253, 0.562415781, 0.676497271, 
0.804482667, 0.946875605, 1.104079665, 1.276387, 1.46396785, 
1.666861178, 1.884966913, 2.11804018, 2.365687854, 2.627367696, 
2.902390371, 3.189924448, 3.489004397, 3.798541516, 4.117337581, 
4.444100924, 4.777464488, 5.116005406, 5.458265497, 5.802772159, 
6.148059008, 6.492685721, 6.835256598, 7.174437349, 7.508969798, 
7.83768423, 8.159509239, 8.473479016, 8.778738117, 9.074543855, 
9.36026644, 9.635387178, 9.899494936, 10.15228119, 10.39353393, 
10.62313069, 10.84103103, 11.04726864, 11.2419433, 11.42521291, 
11.59728568, 11.75841272, 11.90888095, 12.0490065, 12.17912873, 
12.29960466, 12.41080405, 12.51310496, 12.60688988, 12.69254236, 
12.77044409, 12.8409724, 12.90449825, 12.94097991, 12.96138444, 
12.96991286, 12.99795163, 13.0119843, 13.02501736, 13.05102594, 
13.05664057, 13.07588777, 13.09568454, 13.09950733, 13.12178296, 
13.12943549, 13.14260635, 13.15820024, 13.1618623, 13.17942822, 
13.18227288, 13.19517381, 13.20193474, 13.20896059, 13.2174543, 
13.22064151, 13.22908741, 13.23006048, 13.23705198, 13.23707738, 
13.24144057, 13.24165537, 13.24304054)), .Names = c("x", "type","y"), class = "data.frame", row.names = c(NA, -300L))
exdata_type1= subset(data, type=="1")
exdata_type2= subset(data, type=="2") 
exdata_type3= subset(data, type=="3")
plot(exdata_type1$x, exdata_type1$y, xlab='X', ylab='Y', type='l', xlim=    c(100,10000), ylim= c(0.00103, 40),cex.lab=2, cex.axis=2.45, cex.main=2, cex.sub=2.45, cex = 2.25, lty = 1, lwd = 1, tck = F)
par(new=T)
plot(exdata_type2$x, exdata_type2$y, xlab='', ylab='', type='l', xlim= c(100,10000), ylim= c(0.00103, 40), axes = F, cex = 2, lty = 17, lwd = 1)
par(new=T)
plot(exdata_type3$x, exdata_type3$y, type='l', xlim= c(100,10000), ylim= c(0.00103, 40), xlab='', ylab='', axes = F, cex = 2, lty = 3,lwd = 1)
legend("topright",legend = c("Type 1", "Type 2", "Type 3"), bty = "n", lty = c(1, 17, 3), cex = 2, y.intersp=.5, x.intersp=.13, inset = c(-0.05,0), seg.len=0.70, lwd = 1)
par(new=F)

1 个答案:

答案 0 :(得分:1)

您的x值未排序,因此绘图是水平来回绘制线条。如果首先根据x值对数据进行排序,则会消失。

ED1sort = exdata_type1[order(exdata_type1$x), ]
ED2sort = exdata_type2[order(exdata_type2$x), ]
ED3sort = exdata_type3[order(exdata_type3$x), ]

plot(ED1sort$x, ED1sort $y, xlab='X', ylab='Y', type='l', xlim=    c(100,10000), ylim= c(0.00103, 40),cex.lab=2, cex.axis=2.45, cex.main=2, cex.sub=2.45, cex = 2.25, lty = 1, lwd = 1, tck = F)
par(new=T)
plot(ED2sort$x, ED2sort$y, xlab='', ylab='', type='l', xlim= c(100,10000), ylim= c(0.00103, 40), axes = F, cex = 2, lty = 17, lwd = 1)
par(new=T)
plot(ED3sort$x, ED3sort$y, type='l', xlim= c(100,10000), ylim= c(0.00103, 40), xlab='', ylab='', axes = F, cex = 2, lty = 3,lwd = 1)
legend("topright",legend = c("Type 1", "Type 2", "Type 3"), bty = "n", lty = c(1, 17, 3), cex = 2, y.intersp=.5, x.intersp=.13, inset = c(-0.05,0), seg.len=0.70, lwd = 1)

Sorted data

您可能希望调整图例的位置和边距的大小,以使文本看起来更好。