Dear all, a question concerning the plot range. When I plot at first with linear coordinates, a subsequent polygon() call produces a figure that I expect. However, when I apply a logarithmic scale, two polygons appear. Is it possible to override this behaviour? M. Eger Example: y <- c(1.84147098480790, 1.90929742682568, 1.14112000805987, 0.243197504692072, -0.958924274663133,0.720584501801074, 1.65698659871879, 1.98935824662338, 1.41211848524176,0.45597888911063) plot(y,ylim=c(0.0000000001,2),type="l") plot(y,ylim=c(0.0000000001,2),type="l",log="y") Warning in xy.coords(x, y, xlabel, ylabel, log) : 1 y value <= 0 omitted from logarithmic plot polygon(1:10,y,col="red") -- +------------------------------------------------------- | Marcus Eger | Philipps Universitaet Marburg | Fachbereich Physik AG Neurophysik | Renthof 7 | 35032 Marburg | Tel. +49 6421 282-4169 | Fax +49 6421 282-7034 +------------------------------------------------------- | E-Mail: marcus.eger at physik.uni-marburg.de +------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Marcus Eger wrote:> > Dear all, > > a question concerning the plot range. When I plot > at first with linear coordinates, a subsequent polygon() call produces > a figure that I expect. However, when I apply a logarithmic scale, > two polygons appear. Is it possible to override this behaviour? > > M. Eger > > Example: > > y <- c(1.84147098480790, 1.90929742682568, 1.14112000805987, > 0.243197504692072, -0.958924274663133,0.720584501801074, > 1.65698659871879, 1.98935824662338, 1.41211848524176,0.45597888911063) > > plot(y,ylim=c(0.0000000001,2),type="l") > > plot(y,ylim=c(0.0000000001,2),type="l",log="y") > Warning in xy.coords(x, y, xlabel, ylabel, log) : > 1 y value <= 0 omitted from logarithmic plot > > polygon(1:10,y,col="red") >In your case, the fifth y value is ommitted, so polygone cannot work as you are expecting. The following should work: y <- c(1.84147098480790, 1.90929742682568, 1.14112000805987, 0.243197504692072, -0.958924274663133,0.720584501801074, 1.65698659871879, 1.98935824662338, 1.41211848524176,0.45597888911063) plot(y,ylim=c(0.0000000001,2),type="l",log="y") x <- 1:10 temp <- which(y<0) polygon(x[-temp], y[-temp], col="red") Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Uwe Ligges wrote:> > Marcus Eger wrote: > > > > Dear all, > > > > a question concerning the plot range. When I plot > > at first with linear coordinates, a subsequent polygon() call produces > > a figure that I expect. However, when I apply a logarithmic scale, > > two polygons appear. Is it possible to override this behaviour? > > > > > In your case, the fifth y value is ommitted, so polygone cannot work as > you are expecting. > The following should work: > > y <- c(1.84147098480790, 1.90929742682568, 1.14112000805987, > 0.243197504692072, -0.958924274663133,0.720584501801074, > 1.65698659871879, 1.98935824662338, 1.41211848524176,0.45597888911063) > > plot(y,ylim=c(0.0000000001,2),type="l",log="y") > > x <- 1:10 > temp <- which(y<0) > polygon(x[-temp], y[-temp], col="red") > > Uwe LiggesYes it works... now only one polygon appears. However, in the linear plot (log="") the drawn lines are extrapolated until they reach the plot boundary, i.e. the polygon polygon(x, y, col="red") is clipped by the boundary. On the other hand, using log="" this extrapolation is not done because the negative value is omitted. I actually wished this value would not just be omitted. It could simply lie outside the range - and thus, there could be a vertical extrapolation line indicating it. The whole thing is important for me because I want to fill the area below the curve. Marcus Eger -- +------------------------------------------------------- | Marcus Eger | Philipps Universitaet Marburg | Fachbereich Physik AG Neurophysik | Renthof 7 | 35032 Marburg | Tel. +49 6421 282-4169 | Fax +49 6421 282-7034 +------------------------------------------------------- | E-Mail: marcus.eger at physik.uni-marburg.de +------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Marcus Eger wrote:> Yes it works... now only one polygon appears. However, in the linear > plot (log="") > the drawn lines are extrapolated until they reach the plot boundary, > i.e. the polygon > polygon(x, y, col="red") is clipped by the boundary. > On the other hand, using log="" this extrapolation is not done because > the negative > value is omitted. I actually wished this value would not just be > omitted. > It could simply lie outside the range - and thus, there could be a > vertical extrapolation > line indicating it. > > The whole thing is important for me because I want to fill the area > below the curve. > > Marcus EgerAnother quick hack in the evening (and looks ugly so far). Hope it helps. Uwe Ligges y <- c(1.84147098480790, 1.90929742682568, 1.14112000805987, 0.243197504692072, -0.958924274663133,0.720584501801074, 1.65698659871879, 1.98935824662338, 1.41211848524176,0.45597888911063) x <- 1:length(y) plot(y,ylim=c(0.0000000001,2),type="l",log="y") temp <- which(y < 0) down <- 10^par("usr")[3] ## The next two lines will only work for one negative value, ## in other cases you will have to loop (?, no idea to vectorize it) ## over similar lines. x2 <- x[c(1:(temp - 1), temp - 1, temp + 1, (temp + 1) : length(y))] y2 <- c(y[1:(temp - 1)], down, down, y[(temp + 1) : length(y)]) polygon(x2, y2, col="red") -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._