我有下表
agrup1
loaddate recup recup_gente
1 2014-04-16 0.4213183 0.7294452
2 2014-05-16 0.4539847 0.7587836
3 2014-06-16 0.4506581 0.7597915
4 2014-07-16 0.4500220 0.7682811
5 2014-08-16 0.4402933 0.4488161
6 2014-09-01 0.5365479 0.6765825
7 2014-10-01 0.5069230 0.6782983
8 2014-11-01 0.7598421 0.8134287
9 2014-12-03 0.7477045 0.8073076
10 2015-01-05 0.5060155 0.5814931
我需要用2轴做图表。我的代码是:
par(mar=c(4,5,4,4))
plot(agrup1$loaddate[agrup1$loaddate<'2015-01-01'],
agrup1$recup[agrup1$loaddate<'2015-01-01'], yaxt='n', ylab='',
type='o', xlab='fecha de carga',
main='Recupero alcanzado por mes', cex.main=.9,
ylim=c((min(agrup1$recup)-0.1),(max(agrup1$recup)+0.1)))
par(new = T)
plot(agrup1$loaddate[agrup1$loaddate<'2015-01-01'],
agrup1$recup_gente[agrup1$loaddate<'2015-01-01'],
yaxt='n', ylab='', xlab='', type='o', col='red',
, cex.main=.9 ,
ylim=c((min(agrup1$recup_gente)-0.1),(max(agrup1$recup_gente)+0.1)))
axis(2, at=pretty(agrup1$recup[agrup1$loaddate<'2015-01-01']),
lab=paste(round(pretty(agrup1$recup[agrup1$loaddate<'2015-01-01'])*100,2), '%'),
las=1)
axis(4, at=pretty(agrup1$recup_gente[agrup1$loaddate<'2015-01-01']),
lab=paste(round(pretty(agrup1$recup_gente[agrup1$loaddate<'2015-01-01'])*100,2), '%'),
las=1, col='red', col.axis='red')
mtext(side = 2, line = 2.8, "recupero $")
mtext(side = 4, line = 2.8, "recupero clientes", col='red')
我得到以下图表:
我想在两个轴上都有相同的空间...轴一个标记应该是10%,不计算每次多5%。我怎么能这样做?
答案 0 :(得分:0)
我建议在此图中使用1轴。
agrup1 = structure(list(loaddate = structure(c(16176, 16206, 16237, 16267,
16298, 16314, 16344, 16375, 16407, 16440), class = "Date"), recup = c(0.4213183,
0.4539847, 0.4506581, 0.450022, 0.4402933, 0.5365479, 0.506923,
0.7598421, 0.7477045, 0.5060155), recup_gente = c(0.7294452,
0.7587836, 0.7597915, 0.7682811, 0.4488161, 0.6765825, 0.6782983,
0.8134287, 0.8073076, 0.5814931)), .Names = c("loaddate", "recup",
"recup_gente"), row.names = c(NA, -10L), class = "data.frame")
par(mar=c(4,5,4,4))
plot(agrup1$loaddate[agrup1$loaddate<'2015-01-01'],
agrup1$recup[agrup1$loaddate<'2015-01-01'], yaxt='n', ylab='',
type='o', xlab='fecha de carga',
main='Recupero alcanzado por mes', cex.main=.9,
ylim=c((min(agrup1$recup)-0.1),(max(agrup1$recup)+0.1)))
lines(agrup1$loaddate[agrup1$loaddate<'2015-01-01'],
agrup1$recup_gente[agrup1$loaddate<'2015-01-01'],
type='o', col='red', cex.main=.9)
axis(2, at=pretty(seq(0.4,0.8,0.1)),
lab=paste0(seq(40,80,10), '%'),
las=1)
axis(4, at=pretty(seq(0.4,0.8,0.1)),
lab=paste0(seq(40,80,10), '%'),
las=1, col='red', col.axis='red')
mtext(side = 2, line = 2.8, "recupero $")
mtext(side = 4, line = 2.8, "recupero clientes", col='red')