[R] [newbie] scatterplot with marginal histograms (done) and axes labels
Hello, I am stuck when I want to add axes labels to my scatterplot with histograms. I guess it must be something with par(mar=) or so, but could someone give me a hint? Here is what I got so far: # adapted from http://www.stat.ucl.ac.be/ISdidactique/comment/fichiers/r/scatterhist.rs and from ?layout # # see also: # - http://biom1.univ-lyon1.fr/ADE-4/ade4-html/s.hist.html (a function called s.hist in package ade4) # - http://www.statmethods.net/graphs/scatterplot.html (shows how to do some nice scatterplots, # e.g. with the function scatterplot in package car) scatterhist=function(x,y, xlab=, ylab=){ #oldpar = par(no.readonly = TRUE) # save default, for resetting... zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE) layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5)) xhist - hist(x, plot=FALSE) yhist - hist(y, plot=FALSE) top - max(c(xhist$counts, yhist$counts)) par(mar=c(3,3,1,1)) plot(x,y, xlab=xlab, ylab=ylab) par(mar=c(0,3,1,1)) barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0) par(mar=c(3,0,1,1)) barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE) #par(oldpar) # reset to default } Now if I do x=rnorm(50) y=rnorm(50) scatterhist(x,y,xlab=x, ylab=y) there are no axes labels. I also wonder why R complains if I uncomment the first and last line in the function (invalid value for parameter fig specified). Any hint appreciated, Karsten. -- View this message in context: http://www.nabble.com/-newbie--scatterplot-with-marginal-histograms-%28done%29-and-axes-labels-tp20381450p20381450.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] [newbie] scatterplot with marginal histograms (done) and axes labels
Hello, sometimes it helps if I formulate my problem. I tried the following after I posted my previous post. scatterhist=function(x,y, xlab=, ylab=){ #oldpar = par(no.readonly = TRUE) # save default, for resetting... zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE) layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5)) xhist - hist(x, plot=FALSE) yhist - hist(y, plot=FALSE) top - max(c(xhist$counts, yhist$counts)) par(mar=c(3,3,1,1)) plot(x,y) par(mar=c(0,3,1,1)) barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0) par(mar=c(3,0,1,1)) barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE) par(oma=c(3,3,0,0)) mtext(xlab, side=1, line=1, outer=TRUE, adj=0) mtext(ylab, side=2, line=1, outer=TRUE, adj=0) #par(oldpar) # reset to default } This works quite nice in the R Gui (the labels appear, but it is not easy for me to center them). However, when I use the function in a Sweave context, i.e. \begin{Scode}{fig=true, echo=false, results=hide} print(scatterhist(x,y, x, y)) \end{Scode} the labels still do not appear... Kind regards, Karsten. KarstenW wrote: Hello, I am stuck when I want to add axes labels to my scatterplot with histograms. I guess it must be something with par(mar=) or so, but could someone give me a hint? Here is what I got so far: # adapted from http://www.stat.ucl.ac.be/ISdidactique/comment/fichiers/r/scatterhist.rs and from ?layout # # see also: # - http://biom1.univ-lyon1.fr/ADE-4/ade4-html/s.hist.html (a function called s.hist in package ade4) # - http://www.statmethods.net/graphs/scatterplot.html (shows how to do some nice scatterplots, # e.g. with the function scatterplot in package car) scatterhist=function(x,y, xlab=, ylab=){ #oldpar = par(no.readonly = TRUE) # save default, for resetting... zones=matrix(c(2,0,1,3),ncol=2,byrow=TRUE) layout(zones,widths=c(4/5,1/5),heights=c(1/5,4/5)) xhist - hist(x, plot=FALSE) yhist - hist(y, plot=FALSE) top - max(c(xhist$counts, yhist$counts)) par(mar=c(3,3,1,1)) plot(x,y, xlab=xlab, ylab=ylab) par(mar=c(0,3,1,1)) barplot(xhist$counts, axes=FALSE, ylim=c(0, top), space=0) par(mar=c(3,0,1,1)) barplot(yhist$counts, axes=FALSE, xlim=c(0, top), space=0, horiz=TRUE) #par(oldpar) # reset to default } Now if I do x=rnorm(50) y=rnorm(50) scatterhist(x,y,xlab=x, ylab=y) there are no axes labels. I also wonder why R complains if I uncomment the first and last line in the function (invalid value for parameter fig specified). Any hint appreciated, Karsten. -- View this message in context: http://www.nabble.com/-newbie--scatterplot-with-marginal-histograms-%28done%29-and-axes-labels-tp20381450p20382242.html Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Work with packages without using R CMD build/install
Hello, for my small project I would like to organize the data, functions and documentation as a package. I have already created a skeleton directory structure with DESCRIPTION file and put some files in the R, man and data subdirectories. Now I would like to work on the package without calling R CMD build/install after each change. In fact, I do not have the build tools installed yet (I am on Windows) and hope to get along without them (using r-forge). Currently, I do not plan to use C or Fortran extensions. But when I run in the R (2.7.2) console library(mypkg, lib.loc=mypath) the system answers that there is no package named 'mypkg'. Is it possible to use the package infrastructure without calling R CMD ... after each change? Kind regards, Karsten Weinert. -- View this message in context: http://www.nabble.com/Work-with-packages-without-using-R-CMD-build-install-tp19510486p19510486.html Sent from the R help mailing list archive at Nabble.com. __ 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.
[R] Time Series x-axis labeling
Hello, how is it possible to plot a time series of monthly data over several years such that the x-axis shows the first letter of the month and displays a grid line at every year? I am new to R and had no real success until now. I have: library(utils) oneMonth = 1.0 / 12.0 tsData = ts(rnorm(103,100), start=2000, deltat=oneMonth) # goes until Jul 2008, real data plot(tsData, ylab=Values, xlab=Zeit, axes=FALSE) axis(2) # as is atX=seq(from=time(tsData)[1], to=time(tsData)[length(tsData)], by=oneMonth) labMonths= c(J,F,M,A,M,J,J,A,S,O,N,D) labX = rep(labMonths, length.out=length(tsData)) axis(1, at=atX, label=labX) But here I am stuck. First, I do not know how to add the years. And then, I would like to show all the labels, but only few of the months are displayed. Any hint appreciated, kind regards, Karsten. -- View this message in context: http://www.nabble.com/Time-Series-x-axis-labeling-tp19378906p19378906.html Sent from the R help mailing list archive at Nabble.com. __ 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.