J'ai plusieurs graphiques des concentrations en fonction des années et de la profondeur de prélèvement (voir image) sur lesquels j'aimerais mettre deux ou plusieurs couleurs en fond en alternance en fonction des années. J'ai fait un exemple de ce que je veux sur illustrator (visible sur le lien suivant). je ne vois pas du tout comment faire.
https://www.dropbox.com/s/dygbxvve3murqsq/Capture%20d%27%C3%A9cran%202015-05-14%2009.40.02.png?dl=0
Voici mon script pour faire le graphique ainsi qu'un exemple de données
Code : Tout sélectionner
par(mfrow=c(1,8))
for (i in colnames(xrf5)[3:10]) {
x <- xrf5[,i]; y <- xrf5[,"composite.depth"]; z <- xrf5[,"year_full"]
souslabel<-unlist(sapply(rle(z)$lengths,function(x) 1:x))
label1<-paste(z,souslabel,sep=".")
cha<- as.factor(label1)
# create extra margin room on the right for an axis
par(mar=c(5, 5, 4, 5))
# plot x vs. y
plot(x, y,type="l", pch=16, col="black",
yaxt="n", lty=1, xlab="", ylab="", ylim = rev(range(xrf3[,"composite.depth"])))
# draw an axis on the left
axis(2, at=y,labels=(y), col.axis="red", las=2,cex.axis=0.3, tck=-.02)
grid(,100, col = "purple1",
lty = "dotted",
lwd = 1)
par(new=TRUE)
# add x vs. z
plot(x, cha, type="b", pch=8, col=rgb(0, 0.5, 0.7,alpha=0), lty=2,yaxt="n")
# draw an axis on the right, with smaller text and ticks
axis(4, at=cha,labels=paste(z),
col.axis="blue", las=2, cex.axis=0.3, tck=-.02)
# add a title for the right axis
mtext("Years", side=4, line=3, cex.lab=1,las=3, col="black")
# add a main title and bottom and left axis labels
title(paste(i, "-XRF profile"), xlab=paste(i, "(/kcps)"),
ylab="profondeur (mm)"
)
}
Code : Tout sélectionner
composite.depth year Al Si Ca Zn year_full
1 0.1 <NA> 0.000000000 0.000000000 0.01454545 0.033655523 2011
2 0.2 <NA> 0.000000000 0.000436172 0.01501160 0.007378583 2011
3 0.3 <NA> 0.000000000 0.000246960 0.01572314 0.000000000 2011
4 0.4 <NA> 0.000321730 0.002849606 0.02132609 0.000000000 2011
5 0.5 <NA> 0.000786997 0.004259042 0.02615607 0.006249681 2011
6 0.6 <NA> 0.001126383 0.005091252 0.02766397 0.008560512 2011
7 0.7 <NA> 0.001598099 0.006638259 0.02950337 0.011637441 2011
8 0.8 <NA> 0.001223572 0.006693659 0.03382817 0.014538914 2011
9 0.9 <NA> 0.000581450 0.007798265 0.03481857 0.018435373 2011
10 1.0 <NA> 0.001509006 0.008824402 0.03526480 0.018632938 2011
11 1.1 <NA> 0.000603871 0.008454197 0.03912450 0.016463435 2011
12 1.2 <NA> 0.000000000 0.008822382 0.03902086 0.017455035 2011
13 1.3 <NA> 0.001552920 0.008461829 0.04211899 0.017494118 2011
14 1.4 <NA> 0.000477181 0.010847924 0.04138753 0.014601751 2011
15 1.5 <NA> 0.001148499 0.011772119 0.04361107 0.017833643 2011
16 1.6 2011 0.001560828 0.011403604 0.04179198 0.020290770 2011
17 1.7 <NA> 0.002276676 0.012015792 0.04382602 0.021154118 2010
18 1.8 <NA> 0.001663461 0.012209176 0.04485068 0.019427969 2010
19 1.9 2010 0.001398783 0.014236505 0.04441914 0.022225112 2010
20 2.0 <NA> 0.002613637 0.013529415 0.04393985 0.024660434 2009
21 2.1 2009 0.000520058 0.013674457 0.04894660 0.022943720 2009
22 2.2 <NA> 0.002365972 0.013194846 0.04783511 0.024569713 2008
23 2.3 2008 0.001413935 0.013327093 0.04527601 0.025631338 2008
24 2.4 2007 0.001773155 0.014816366 0.04375787 0.020316153 2007
25 2.5 <NA> 0.000954130 0.012850939 0.04400925 0.021915174 2006
26 2.6 2006 0.000943874 0.011709934 0.04471602 0.023567347 2006
27 2.7 <NA> 0.001778258 0.011427495 0.04358190 0.021368250 2005
28 2.8 <NA> 0.000486832 0.011368954 0.04218254 0.022967005 2005
29 2.9 <NA> 0.000788350 0.011431082 0.04088160 0.024100999 2005
30 3.0 2005 0.000836473 0.011320262 0.04173998 0.023616408 2005
31 3.1 <NA> 0.001241690 0.010816502 0.03821647 0.021136328 2004
32 3.2 2004 0.000000000 0.009924936 0.03794336 0.018762589 2004
33 3.3 <NA> 0.000509594 0.009993695 0.03490716 0.018628475 2003
34 3.4 <NA> 0.001407626 0.008215939 0.03323721 0.014076258 2003
35 3.5 <NA> 0.000000000 0.008261697 0.03281406 0.015737951 2003
36 3.6 <NA> 0.000411052 0.006664914 0.03358882 0.016999935 2003
37 3.7 <NA> 0.000712805 0.005256937 0.03139312 0.012236486 2003
38 3.8 <NA> 0.000846224 0.005258680 0.02922496 0.015745817 2003
39 3.9 <NA> 0.000548658 0.005303689 0.03115155 0.015392891 2003
40 4.0 <NA> 0.000580422 0.006048605 0.03060961 0.012097210 2003
41 4.1 <NA> 0.000580334 0.005009195 0.03078822 0.015913357 2003
42 4.2 <NA> 0.000429990 0.006081286 0.02948502 0.015356783 2003
43 4.3 <NA> 0.000399289 0.005805054 0.03037671 0.015725861 2003
44 4.4 <NA> 0.000000000 0.006240930 0.03030868 0.013130670 2003
45 4.5 <NA> 0.000618296 0.006955831 0.03246055 0.016292102 2003
46 4.6 <NA> 0.000000000 0.007284253 0.03346398 0.018833218 2003
47 4.7 <NA> 0.000656332 0.008157275 0.03156647 0.013595459 2003
48 4.8 <NA> 0.001534035 0.007294494 0.03027372 0.015778649 2003
49 4.9 <NA> 0.000155493 0.007152683 0.03560792 0.018659172 2003
50 5.0 <NA> 0.001084178 0.007589244 0.03292803 0.019081528 2003
51 5.1 <NA> 0.000215398 0.006892728 0.03215581 0.013631601 2003
52 5.2 <NA> 0.001073330 0.008341309 0.03134124 0.016927950 2003
53 5.3 2003 0.000000000 0.007684386 0.03104865 0.013253232 2003
Merci d'avance pour votre aide
Arnaud