Hi, I'd like to plot a boxplot and use a scatter.smooth line plot as an overlay for this plot. This works except for the problem that the x-axis ticks for both plots are differently spaced: The boxplot ticks are closer and the space between the outer most boxplots and the plot region (box) is larger for boxplots than for the scatter.smooth plot. Is there any plot-option that can be changed to produce the desired plot. Here an example to illustrate what problem I am facing: x <- c(rep(1,100),rep(2,100),rep(3,100)) y <- c(rnorm(100,1),rnorm(100,2),rnorm(100,3)) boxplot(y~x) par(new=TRUE) scatter.smooth(x, y, xaxt="n", yaxt="n", ann=FALSE) Moreover, I'd like to plot just the smoothed line only and not the datapoints. Any suggestions? best regards, J. [[alternative HTML version deleted]]
Use lines() with loess.smooth() instead of scatter.smooth() to add to the already existing boxplot. For example, boxplot(y~x) lines(loess.smooth(x, y)) Jean On Tue, Nov 19, 2013 at 4:43 AM, Johannes Radinger < johannesradinger@gmail.com> wrote:> Hi, > > I'd like to plot a boxplot and use a scatter.smooth line plot as an overlay > for this plot. > This works except for the problem that the x-axis ticks for both plots are > differently spaced: > The boxplot ticks are closer and the space between the outer most boxplots > and the plot region (box) is larger for boxplots than for the > scatter.smooth plot. Is there any plot-option that can be changed to > produce the desired plot. > > Here an example to illustrate what problem I am facing: > > x <- c(rep(1,100),rep(2,100),rep(3,100)) > y <- c(rnorm(100,1),rnorm(100,2),rnorm(100,3)) > > boxplot(y~x) > par(new=TRUE) > scatter.smooth(x, y, xaxt="n", yaxt="n", ann=FALSE) > > Moreover, I'd like to plot just the smoothed line only and not the > datapoints. > Any suggestions? > > best regards, > > J. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
On Nov 19, 2013, at 2:43 AM, Johannes Radinger wrote:> Hi, > > I'd like to plot a boxplot and use a scatter.smooth line plot as an overlay > for this plot. > This works except for the problem that the x-axis ticks for both plots are > differently spaced: > The boxplot ticks are closer and the space between the outer most boxplots > and the plot region (box) is larger for boxplots than for the > scatter.smooth plot. Is there any plot-option that can be changed to > produce the desired plot. > > Here an example to illustrate what problem I am facing: > > x <- c(rep(1,100),rep(2,100),rep(3,100)) > y <- c(rnorm(100,1),rnorm(100,2),rnorm(100,3)) > > boxplot(y~x) > par(new=TRUE) > scatter.smooth(x, y, xaxt="n", yaxt="n", ann=FALSE) > > Moreover, I'd like to plot just the smoothed line only and not the > datapoints.?boxplot # .... sends you to ?boxplot.stats which should be used to determine what user coordinates are being used when plotting the boxplot. xlim would be suitable for getting both plots on hte same x-scale.>-- David Winsemius Alameda, CA, USA