n.vialma@libero.itg wrote on 12/16/2011 05:02:24 AM:
> Dear all,
> I'm having problems with the tick of my graph. I'mpcombining lines
and
> barplot.
> For my I'm using the function axis combined with the function pretty to
have > more efficient tick, but all my tick (for example, 300 as my max
> tick and -100
> as my min tick) are not printed on my graph.
> So I would like to have for the left axis the seq from 0 to 100 (with 0
and > 100 printed on my graph) and for the right axis the seq from -100 to300
(with > -100 and 300 printed on my graph)
> Someone Knows how to get it???
>
>
> The code and data are:
> grafico<-{
>
> pdf(file=file, paper="special",width=30, height=20)
> par(bg="white",font=3,font.axis=3,las=1,cex.axis=2.2,
mar=c(8,6,8,8)+8)> barplot(Imp$TassoV, width=10,space=c(0,0.1),legend.text =
> FALSE,beside=TRUE,
> border="grey40",
main="",col="midnightblue",cex.main=2.4,
> axes = FALSE, axisnames =FALSE)
> lab=as.character(pretty(Imp$TassoV))
> axis(side=4,at=pretty(Imp$TassoV),labels=lab,cex.axis=2.4)
> par(new=T)
> chart.TimeSeries(Imp$ValueA, type="l", lwd=8,
main="", ylab="",
> xlab="", date.
> format="%y",
> col="red3",major.ticks="years",minor.ticks=TRUE,
grid.color="grey50",
grid.> lty="dotted", cex.axis=2.4,yaxis=FALSE)
> axis(2,at=c(pretty(Imp$ValueA)))
> legend("topleft",c("Livelli mln $ (sc.
sx)","Tasso di var.
(sc.dx)"),col=c> ("red3",
"midnightblue"),bty="n",lwd=4,cex=2.4)
> }
> dev.off()
>
> ValueA ValueA_L TassoV
> 1995-12-16 88.06557 NA NA
> 1996-12-16 88.34237 88.06557 0.3143044
> 1997-12-16 57.86447 88.34237 -34.4997529
> 1998-12-16 50.19389 57.86447 -13.2561039
> 1999-12-16 23.06846 50.19389 -54.0412943
> 2000-12-16 45.79965 23.06846 98.5379304
> 2001-12-16 22.35262 45.79965 -51.1947722
> 2002-12-16 66.89223 22.35262 199.2589371
> 2003-12-16 89.24867 66.89223 33.4215852
> 2004-12-16 77.16459 89.24867 -13.5397854
> 2005-12-16 51.23656 77.16459 -33.6009462
> 2006-12-16 49.51073 51.23656 -3.3683450
> 2007-12-16 90.39337 49.51073 82.5732837
> 2008-12-16 38.84831 90.39337 -57.0230554
> 2009-12-16 14.70859 38.84831 -62.1384086
> 2010-12-16 55.23819 14.70859 275.5505995
>
>
> Thanks for your attention
You did well to include example data and code in your query. You would
likely have received a more rapid reply if you had made your example
simpler, leaving out details that are not relevant to your question. Also,
it is very helpful to the readers of this list if you share your data
using the output of dput(), so that it is easy to read in, and each column
is of the appropriate class.
There is no need for you to specify tick marks using the pretty()
function, as this is what most R graphing functions use by default. In
order to extend the limits on the yaxis, use the ylim= argument in the
graphing functions. A much simplified version of your graph is created by
the code below.
Jean
Imp <- structure(list(ValueA = structure(c(88.06557, 88.34237, 57.86447,
50.19389, 23.06846, 45.79965, 22.35262, 66.89223, 89.24867, 77.16459,
51.23656, 49.51073, 90.39337, 38.84831, 14.70859, 55.23819), .Dim = c(16L,
1L), index = structure(c(819093600, 850716000, 882252000, 913788000,
945324000, 976946400, 1008482400, 1040018400, 1071554400, 1103176800,
1134712800, 1166248800, 1197784800, 1229407200, 1260943200, 1292479200
), tzone = "", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS =
"Date", .indexTZ = ""),
ValueA_L = c(NA, 88.06557, 88.34237, 57.86447, 50.19389,
23.06846, 45.79965, 22.35262, 66.89223, 89.24867, 77.16459,
51.23656, 49.51073, 90.39337, 38.84831, 14.70859), TassoV = c(NA,
0.3143044, -34.4997529, -13.2561039, -54.0412943, 98.5379304,
-51.1947722, 199.2589371, 33.4215852, -13.5397854, -33.6009462,
-3.368345, 82.5732837, -57.0230554, -62.1384086, 275.5505995
)), .Names = c("ValueA", "ValueA_L",
"TassoV"), row.names =
c("1995-12-16",
"1996-12-16", "1997-12-16", "1998-12-16",
"1999-12-16", "2000-12-16",
"2001-12-16", "2002-12-16", "2003-12-16",
"2004-12-16", "2005-12-16",
"2006-12-16", "2007-12-16", "2008-12-16",
"2009-12-16", "2010-12-16"
), class = "data.frame")
par(las=1, mar=c(5, 4, 4, 4)+0.1)
barplot(Imp$TassoV, ylim=c(-100, 300), axes=FALSE)
axis(4)
par(new=T, yaxs="i")
chart.TimeSeries(Imp$ValueA, date.format="%y", ylim=c(0, 100),
major.ticks="years", xlab="")
[[alternative HTML version deleted]]