Katharina May
2009-Jun-17 09:24 UTC
[R] lattice: axis ticks, axis alignment and remove axis from plot
Hi there, I'm a bit confused concerning the axis tck setting in the lattice package as the ticks on left sided axis aren't drawn at all with the following setting: dados <- data.frame(varsep = factor(rep(1:2,10)), i = runif(20)) library(lattice) my.theme <- list( axis.components = list(left = list(tck = 1, pad1 = 1, pad2 2), top = list(tck = 0, pad1 = 1, pad2 = 0), right = list(tck = 0, pad1 = 1, pad2 = 0), bottom = list(tck = +0.5, pad1 = 1, pad2 = 2))) trellis.par.set(theme = my.theme) bwplot(varsep ~ i, dados, xlab = names(dados)[1], ylab = names(dados)[2], panel = function(...) { panel.grid(v = -1, h = 0) panel.bwplot(...) }) Maybe somebody can help me recognise the problem why the left sided ticks are not drawn. I'm also wondering how to tell the trellis object not to draw the right and top axes at all an how to align the y axis that it goes through x=0? Thanks, Katharina
katharina
2009-Jun-17 18:48 UTC
[R] lattice: axis ticks, axis alignment and remove axis from plot
Hi *, I solved the tick problem somehow (or rather I noticed that they are actually drawn on a xyplot which is there I really want them), but I'm still wondering and cannot find any information on that, how I align my axis in a xyplot that they both go through 0 (leftsided y-axis through x=0, x-axis at the bottom through y=0). And is there a way to have the top axis and right axis not drawn at all? I managed to get rid of the ticks, but not any further... Hope somebody can help me struggling with lattice, Thanks, Katharina katharina wrote:> > Hi there, > > I'm a bit confused concerning the axis tck setting in the lattice > package as the ticks on left sided axis aren't > drawn at all with the following setting: > > dados <- data.frame(varsep = factor(rep(1:2,10)), > i = runif(20)) > > library(lattice) > > my.theme <- list( > axis.components = list(left = list(tck = 1, pad1 = 1, pad2 > 2), top = list(tck = 0, pad1 = 1, pad2 = 0), right = list(tck = 0, > pad1 = 1, pad2 = 0), bottom = list(tck = +0.5, pad1 = 1, pad2 = 2))) > > trellis.par.set(theme = my.theme) > > > bwplot(varsep ~ i, dados, > xlab = names(dados)[1], > ylab = names(dados)[2], > panel = function(...) { > panel.grid(v = -1, h = 0) > panel.bwplot(...) > }) > > > > Maybe somebody can help me recognise the problem why the left sided > ticks are not drawn. > > I'm also wondering how to tell the trellis object not to draw the > right and top axes at all an how to align the y axis > that it goes through x=0? > > Thanks, > > Katharina > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- View this message in context: http://www.nabble.com/lattice%3A-axis-ticks%2C-axis-alignment-and-remove-axis-from-plot-tp24070012p24079731.html Sent from the R help mailing list archive at Nabble.com.
Katharina May
2009-Jun-18 10:36 UTC
[R] lattice: axis ticks, axis alignment and remove axis from plot
Hi Sorn, thanks for your code. I guess I didn't really made myself very clear. What I sort of looking for is a xyplot with both the x axis at the bottom and y axis at the left going through 0, but continuing in the positive and negative area (forming a kind of cross like e.g. http://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Erf_plot.svg/600px-Erf_plot.svg.png I'm not sure if this possible at all or if I just have to add to reference lines at x=0 and y =0 as a workaround even though not fully satisfying...? Thanks, Katharina 2009/6/18 <Sorn.Norng@dpi.vic.gov.au>> > Hi Katharina, > > Look at using scales - here is an example of my code > > > xyplot(SA~Dates,data=dm,type="b",cex=1.5,col=2, > xlab=list(label="Sampling dates",cex=2.0), > ylab=list(label="Total dry matter (t/ha)",cex=2.0), > *scales=list(cex=1.2, tck=c(1,0), x = list(rot = 90)) * > ) > > > Cheers > > Sorn > > scales list determining how the x- and y-axes (tick marks and labels) are > drawn. The list contains parameters in name=value form, and may also > contain two other lists called x and y of the same form (described below). > Components of x and y affect the respective axes only, while those in > scales affect both. When parameters are specified in both lists, the > values in x or y are used. Note that certain high-level functions have > defaults that are specific to a particular axis (e.g., bwplot has > alternating=FALSE for the y-axis only); these can be overridden only by an > entry in the corresponding component of scales. > The possible components are : > relation > character string that determines how axis limits are calculated for each > panel. Possible values are "same" (default), "free" and "sliced". For > relation="same", the same limits, usually large enough to encompass all > the data, are used for all the panels. For relation="free", limits for > each panel is determined by just the points in that panel. Behavior for > relation="sliced" is similar, except that the length (max - min) of the > scales are constrained to remain the same across panels. > The determination of what axis limits are suitable for each panel can be > controlled by the prepanel function, which can be overridden by xlim, ylimor > scales$limits. If relation is not "same", the value of xlim etc is > normally ignored, except when it is a list, in which case it is treated as > if its components were the limit values obtained from the prepanel > calculations for each panel. > tick.number > Suggested number of ticks (ignored for a factor, shingle or character > vector, in which case there is no natural rule for leaving out some of the > labels. But see xlim). > draw > logical, defaults to TRUE, whether to draw the axis at all. > alternating > logical specifying whether axis labels should alternate from one side of > the group of panels to the other. For finer control, alternating can be a > vector (replicated to be as long as the number of rows or columns per page) > consisting of the following numbers > > - 0: do not draw tick labels > - 1: bottom/left > - 2: top/right > - 3: both. > > alternating applies only when relation="same". The default is TRUE, or > equivalently, c(1, 2) > limits > same as xlim and ylim. > at > location of tick marks along the axis (in native coordinates), or a list as > long as the number of panels describing tick locations for each panel. > labels > Labels (strings or expressions) to go along with at. Can be a list like atas well. > cex > numeric multiplier to control character sizes for axis labels. Can be a > vector of length 2, to control left/bottom and right/top separately. > font, fontface, fontfamily > specifies font for axis labels. > tck > numeric to control length of tick marks. Can be a vector of length 2, to > control left/bottom and right/top separately. > col > color of ticks and labels. > rot > Angle by which the axis labels are to be rotated. Can be a vector of length > 2, to control left/bottom and right/top separately. > abbreviate > logical, whether to abbreviate the labels using abbreviate. Can be useful > for long labels (e.g., in factors), especially on the x-axis. > minlength > argument passed to abbreviate if abbreviate=TRUE. > log > Controls whether the corresponding variable (x or y) will be log > transformed before being passed to the panel function. Defaults to FALSE, > in which case the data are not transformed. Other possible values are any > number that works as a base for taking logarithm, TRUE (which is > equivalent to 10), and "e" (for the natural logarithm). As a side effect, > the corresponding axis is labeled differently. Note that this is a > transformation of the data, not the axes. Other than the axis labeling, > using this feature is no different than transforming the data in the > formula; e.g., scales=list(x = list(log = 2)) is equivalent to y ~ log2(x). > > format > the format to use for POSIXct variables. See strptime for description of > valid values. > axs > character, "r" or "i". In the latter case, the axis limits are calculated > as the exact data range, instead of being padded on either side. (May not > always work as expected.) > > > > ---------------------------------------------------------- > Sorn Norng > Biometrician > Department of Primary Industries > Knoxfield Centre > 621 Burwood Highway, Ferntree Gully 3156 > Ph: (03) 9210 9358 > Mob: 0428344515 > Fax: (03) 9800 3521 > Email: sorn.norng@dpi.vic.gov.au > > ----------------------------------------------------------------------------- > > > > *Katharina May <may.katharina@googlemail.com>* > Sent by: r-help-bounces@r-project.org > > 17/06/2009 07:24 PM > To > r-help@r-project.org cc > Subject > [R] lattice: axis ticks, axis alignment and remove axis from plot > > > > > Hi there, > > I'm a bit confused concerning the axis tck setting in the lattice > package as the ticks on left sided axis aren't > drawn at all with the following setting: > > dados <- data.frame(varsep = factor(rep(1:2,10)), > i = runif(20)) > > library(lattice) > > my.theme <- list( > axis.components = list(left = list(tck = 1, pad1 = 1, pad2 > 2), top = list(tck = 0, pad1 = 1, pad2 = 0), right = list(tck = 0, > pad1 = 1, pad2 = 0), bottom = list(tck = +0.5, pad1 = 1, pad2 = 2))) > > trellis.par.set(theme = my.theme) > > > bwplot(varsep ~ i, dados, > xlab = names(dados)[1], > ylab = names(dados)[2], > panel = function(...) { > panel.grid(v = -1, h = 0) > panel.bwplot(...) > }) > > > > Maybe somebody can help me recognise the problem why the left sided > ticks are not drawn. > > I'm also wondering how to tell the trellis object not to draw the > right and top axes at all an how to align the y axis > that it goes through x=0? > > Thanks, > > Katharina > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > Notice: > This email and any attachments may contain information...{{dropped:30}}
Katharina May
2009-Jun-18 11:31 UTC
[R] lattice: axis ticks, axis alignment and remove axis from plot
Hi Jim, thanks, that sounds like a good idea! The only problem is that axis and pos are a far as I know not for lattice or at least I cannot find an appropriate function and way to do this in lattice. Maybe I have to keep on searching for how to realize that with lattice... Best wishes, Katharina 2009/6/18 Jim Lemon <jim at bitwrit.com.au>:> Katharina May wrote: >> >> What I sort of looking for is a xyplot with both the x axis at the bottom >> and y axis at the >> left going through 0, but continuing ?in the positive and negative area >> (forming a kind of cross >> like e.g. >> >> http://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Erf_plot.svg/600px-Erf_plot.svg.png >> >> I'm not sure if this possible at all or if I just have to add to reference >> lines at x=0 and y =0 as a >> workaround even though not fully satisfying...? >> > > Hi Katharina, > I'm not sure if you can do this in lattice, but if you do the original plot > with axes=FALSE, you can specify where the x and y axis are placed with the > pos= argument. > > Jim > >-- Time flies like an arrow, fruit flies like bananas.