将两个Y轴放在图形上时,图形轴缩放不正确

时间:2016-08-22 13:45:50

标签: r plot

有人可以解释为什么我的情节显然会用第二行覆盖第一行吗?这些价值绝不相同。

per.acc<-c(0.508407842930696, 0.508407842930696, 0.508776550216615, 0.508895063272804, 
           0.509619309727288, 0.51039622865119, 0.510712263467692, 0.511871057794867, 
           0.512252933198141, 0.513280046351773, 0.514122805862446, 0.514478345031011, 
           0.514768043612805, 0.515676643710249, 0.516084855348231, 0.51682226992007, 
           0.517757206252222, 0.519008177400877, 0.519890441263613, 0.520680528304868, 
           0.521286261703164, 0.522181693683254, 0.523024453193927, 0.524222751873165, 
           0.524420273633479, 0.524986502679712, 0.525631740430071, 0.52609262453747, 
           0.526777366639891, 0.52733042756877, 0.52788348849765, 0.528278532018277, 
           0.528673575538905, 0.529661184340475, 0.530569784437919, 0.531109677249444, 
           0.530833146785004, 0.531425712065946, 0.531280862775049, 0.53063562502469, 
           0.531465216418009, 0.531215022188278, 0.531188685953569, 0.53153105700478, 
           0.53180758746922, 0.532110454168368, 0.532005109229533, 0.532070949816305, 
           0.53233431216339, 0.532189462872493, 0.532307975928682, 0.532321144046036, 
           0.531741746882448, 0.531504720770071, 0.530214245269354, 0.529661184340475, 
           0.529002778472762, 0.529845537983434, 0.53054344820321, 0.529108123411596, 
           0.528186355196797, 0.527896656615004, 0.526830039109309, 0.526263810063075, 
           0.525091847618546, 0.524354433046707, 0.523538009770743, 0.522655745908008, 
           0.522036844392357, 0.520812209478411, 0.519640247033882, 0.518520957058769, 
           0.517335826496886, 0.515531794419352, 0.514715371143388, 0.51314836517823, 
           0.511831553442804, 0.510975625814777, 0.510040689482625, 0.508118144348902, 
           0.507104199312624, 0.505813723811907, 0.505168486061548, 0.504312558433521, 
           0.503311781514597, 0.502284668360964, 0.501297059559395, 0.500546476870202, 
           0.500072424645448, 0.499018975257107, 0.497886517164641, 0.496964748949843, 
           0.495516256040874, 0.494120435601322, 0.493383021029483, 0.492803623865896, 
           0.492421748462622, 0.492118881763474, 0.492026704941994, 0.491684333890784
)

num.pred<-c(38609L, 38609L, 38637L, 38646L, 38701L, 38760L, 38784L, 38872L, 
            38901L, 38979L, 39043L, 39070L, 39092L, 39161L, 39192L, 39248L, 
            39319L, 39414L, 39481L, 39541L, 39587L, 39655L, 39719L, 39810L, 
            39825L, 39868L, 39917L, 39952L, 40004L, 40046L, 40088L, 40118L, 
            40148L, 40223L, 40292L, 40333L, 40312L, 40357L, 40346L, 40297L, 
            40360L, 40341L, 40339L, 40365L, 40386L, 40409L, 40401L, 40406L, 
            40426L, 40415L, 40424L, 40425L, 40381L, 40363L, 40265L, 40223L, 
            40173L, 40237L, 40290L, 40181L, 40111L, 40089L, 40008L, 39965L, 
            39876L, 39820L, 39758L, 39691L, 39644L, 39551L, 39462L, 39377L, 
            39287L, 39150L, 39088L, 38969L, 38869L, 38804L, 38733L, 38587L, 
            38510L, 38412L, 38363L, 38298L, 38222L, 38144L, 38069L, 38012L, 
            37976L, 37896L, 37810L, 37740L, 37630L, 37524L, 37468L, 37424L, 
            37395L, 37372L, 37365L, 37339L)

plot(x=1:100,y=per.acc, main="RSI predicting trend",ylab=NA,xlab="RSI cutoff value",col="blue",type="p")
par(new=T)
plot(x=1:100,y=num.pred,axes=F,xlab=NA,main=NA,ylab=NA,col="red",type="p")
axis(side=4)

1 个答案:

答案 0 :(得分:0)

因为您的per.accnum.pred具有完美的共线性:

plot(per.acc, num.pred)

enter image description here

因此,您的第二个绘图和第一个绘图只是因垂直位移而不同。当你par(new = TRUE)时,它们会重合。

另一方面,如果你做一些随机改组:

set.seed(0); num.pred <- sample(num.pred)

问题消失了:

enter image description here