Re: [R] Multiple plots; single x(y) labels

2010-05-14 Thread Gurmeet
Hi Xin,

Or, just try adding "oma" and "mtext" commands:

?par
?mtext

# Code
par(mfcol=c(2,2))
par(oma=c(2,2,0,0))
plot(x <- sort(rnorm(7)), type = "s", main = "", ylab="", xlab="")
plot(x <- sort(rnorm(27)), type = "s", main = "", ylab="", xlab="")
plot(x <- sort(rnorm(47)), type = "s", main = "", ylab="", xlab="")
plot(x <- sort(rnorm(67)), type = "s", main = "", ylab="", xlab="")
mtext("One x-label", side = 1, outer=TRUE)
mtext("One y-label", side = 2, outer=TRUE)

~Gurmeet


On Fri, May 14, 2010 at 4:14 AM, Jim Lemon  wrote:

> On 05/14/2010 02:04 AM, Xin Ge wrote:
>
>> Hi All,
>>
>> Can anyone please help me with getting a single x and y-axis label while
>> plotting muliple plots. Here is the code:
>>
>> par(mfcol=c(2,2))
>> plot(x<- sort(rnorm(7)), type = "s", main = "", ylab="", xlab="")
>> plot(x<- sort(rnorm(27)), type = "s", main = "", ylab="", xlab="")
>> plot(x<- sort(rnorm(47)), type = "s", main = "", ylab="", xlab="")
>> plot(x<- sort(rnorm(67)), type = "s", main = "", ylab="", xlab="")
>>
>> also, how can remove x-tick lables using plot()?
>>
>>  Hi Xin,
> Fortunately, this wheel is pretty easy to reinvent:
>
> require(plotrix)
>
> x1<-rnorm(7)
> x2<-rnorm(27)
> x3<-rnorm(47)
> x4<-rnorm(67)
> allxlim<-c(1,67)
> allylim<-range(c(x1,x2,x3,x4))
> panes(matrix(1:4,nrow=2,byrow=TRUE),widths=c(1.1,1),
>  heights=c(1,1.1))
> par(mar=c(0,4,2,0))
> plot(sort(x1),xlim=allxlim,ylim=allylim,type="s",
>  main="",ylab="",xlab="",xaxt="n")
> tab.title("Plot of x1",tab.col="orange")
> par(mar=c(0,0,2,1))
> plot(sort(x2),xlim=allxlim,ylim=allylim,type="s",
>  main="",ylab="",xlab="",xaxt="n",yaxt="n")
> tab.title("Plot of x2",tab.col="orange")
> par(mar=c(4,4,2,0))
> plot(sort(x3),xlim=allxlim,ylim=allylim,type="s",
>  main="",ylab="",xlab="")
> tab.title("Plot of x3",tab.col="orange")
> par(mar=c(4,0,2,1))
> plot(sort(x4),xlim=allxlim,ylim=allylim,type="s",
>  main="",ylab="",xlab="",yaxt="n")
> tab.title("Plot of x4",tab.col="orange")
>
> Jim
>
>
> __
> 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]]

__
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] 'cuts' option in levelplot()

2010-04-20 Thread Gurmeet
Thanks David! :P

On Tue, Apr 20, 2010 at 11:02 PM, David Winsemius wrote:

>
> On Apr 20, 2010, at 10:43 PM, Gurmeet wrote:
>
> Hi All,
>>
>> Does anyone knows what exactly "cuts=some number" (say 15) does in
>> lattice's
>> levelplot(). I doubt this but does it uses cut() internally, something
>> like
>> cut(z, 15)?
>>
>>
> C'mon, man, look at the code:
>
> seq(zrng[1], zrng[2], length.out = cuts + 2)
>
>
> Thanks,
>> Gurmeet
>>
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[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.


[R] 'cuts' option in levelplot()

2010-04-20 Thread Gurmeet
 Hi All,

Does anyone knows what exactly "cuts=some number" (say 15) does in lattice's
levelplot(). I doubt this but does it uses cut() internally, something like
cut(z, 15)?

Thanks,
Gurmeet

[[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.


Re: [R] Multi-panel Pie Charts.

2010-03-24 Thread Gurmeet
Thanks Charlie... I think its worth exploring ggplot2 functionality.

On Wed, Mar 24, 2010 at 4:06 PM, Sharpie  wrote:

>
> > Thanks for your reply Sharpie. I completely understand that it may not be
> > the best to go with muti-panel pie charts, but my group would like to
> have
> > this utility along with barplot/dotplot (may be, using it for proportions
> > data). Thanks,
> >
>
> Well, if the management trolls *DEMAND* pie, then these sites provide a
> good
> start with ggplot2:
>
>
>
> http://learnr.wordpress.com/2009/08/20/ggplot2-version-of-figures-in-lattice-multivariate-data-visualization-with-r-part-13-2/
>
>  http://had.co.nz/ggplot2/coord_polar.html
>
> Using the data I posted before, you could apply those approach with:
>
>  productPie <- qplot( factor(1), value/100, data = productData,
>geom = 'bar', fill = variable,
>xlab = '',
>ylab = '' ) +
>facet_wrap( ~ month, scales = 'free_y' ) +
>coord_polar( theta = 'y' ) +
>scale_y_continuous( formatter = 'percent' ) +
>theme_bw()
>
>  print( productPie )
>
> The beauty of ggplot2 is that that is basically the same chart I posted
> last
> time, the bars have just been "bent" into a pie through the use of
> coord_polar().  It probably needs some fine-tuning, but I'll leave that up
> to you.
>
> Good luck!
>
> -Charlie
>
> -
> Charlie Sharpsteen
> Undergraduate-- Environmental Resources Engineering
> Humboldt State University
> --
> View this message in context:
> http://n4.nabble.com/Multi-panel-Pie-Charts-tp1687026p1689591.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.
>

[[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.


Re: [R] Multi-panel Pie Charts.

2010-03-24 Thread Gurmeet
Hi Jim, exactly what we are expecting. Thanks a lot for your efforts... it
should be really helpful!

On Wed, Mar 24, 2010 at 10:50 PM, Jim Lemon  wrote:

> On 03/25/2010 06:00 AM, Gurmeet wrote:
>
>> Hi All,
>>
>> I'm trying to find out a way to plot multi-panel pie charts. It may not be
>> the best way to present data, but I would still need one.
>>
>> Hi Gurmeet,
> Your message prompted me to finish a little function that I had almost
> forgotten.
>
> panes<-function(nrow=2,ncol=2,mar=c(0,0,1.6,0),oma=c(2,1,1,1)) {
>  oldpar<-par("mar","mfrow","oma")
>  par(mfrow=c(nrow,ncol),mar=mar,oma=oma)
>  return(oldpar)
> }
> oldpar<-panes()
> pie(foo$value[foo$month=="Jan"],labels=foo$variable[foo$month=="Jan"],
>  radius=0.7)
> tab.title("January sales",tab.col="#66")
> box()
> pie(foo$value[foo$month=="Feb"],labels=foo$variable[foo$month=="Feb"],
>  radius=0.7)
> tab.title("February sales",tab.col="#66")
> box()
> pie(foo$value[foo$month=="Mar"],labels=foo$variable[foo$month=="Mar"],
>  radius=0.7)
> tab.title("March sales",tab.col="#66")
> box()
> pie(foo$value[foo$month=="Apr"],labels=foo$variable[foo$month=="Apr"],
>  radius=0.7)
> tab.title("April sales",tab.col="#66")
> box()
> par(xpd=TRUE)
> mtext("First quarter sales",at=-1.2,line=0.8,side=1,cex=1.5)
> par(xpd=FALSE)
> par(oldpar)
>
> Is this what you wanted?
>
> Jim
>
>

[[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.


[R] Multi-panel Pie Charts.

2010-03-24 Thread Gurmeet
Hi All,

I'm trying to find out a way to plot multi-panel pie charts. It may not be
the best way to present data, but I would still need one.

1. Is anyone aware of some in-built script/function which can do this for
me. I'm aware of one given in Deepayan's book, but anything apart from this?


2. I tried using Deepayan's script on following data set but it doesn't seem
to work as expected - labels are getting repeated/overlapping. I'm really
not sure what could be the problem, can anyone help please. I hope data is
in the right format, as expected.

 Data read into object "foo":

variable month value
ProdA   Jan25
ProdA   Feb30
ProdA   Mar25
ProdA   Apr10
ProdB   Jan25
ProdB   Feb30
ProdB   Mar50
ProdB   Apr40
ProdC   Jan40
ProdC   Feb30
ProdC   Mar20
ProdC   Apr40
ProdD   Jan10
ProdD   Feb10
ProdD   Mar 5
ProdD   Apr10

R Code: as it is from the book,

library(lattice)
library(grid)
library(gridBase)

panel.piechart <-
function(x, y, labels = as.character(y),
 edges = 200, radius = 0.8, clockwise = FALSE,
 init.angle = if(clockwise) 90 else 0,
 density = NULL, angle = 45,
 col = superpose.polygon$col,
 border = superpose.polygon$border,
 lty = superpose.polygon$lty, ...)
{
stopifnot(require("gridBase"))
superpose.polygon <- trellis.par.get("superpose.polygon")
opar <- par(no.readonly = TRUE)
on.exit(par(opar))
if (panel.number() > 1) par(new = TRUE)
par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
pie(as.numeric(x), labels = labels, edges = edges, radius = radius,
clockwise = clockwise, init.angle = init.angle, angle = angle,
density = density, col = col, border  = border, lty = lty)
}

piechart <- function(x, data = NULL, panel = "panel.piechart", ...)
{
ocall <- sys.call(sys.parent())
ocall[[1]] <- quote(piechart)
ccall <- match.call()
ccall$data <- data
ccall$panel <- panel
ccall$default.scales <- list(draw = FALSE)
ccall[[1]] <- quote(lattice::barchart)
ans <- eval.parent(ccall)
ans$call <- ocall
ans
}

## Figure 14.5
par(new = TRUE)
piechart(foo)

Thanks in advance,
Gurmeet

[[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.


Re: [R] calling map() in xyplot()

2010-03-10 Thread Gurmeet
Thanks Felix and David. [Actually, don't go by variable name us.map, I was
using an example I found online...]

On Tue, Mar 9, 2010 at 11:43 PM, David Winsemius wrote:

>
> On Mar 9, 2010, at 10:42 PM, Gurmeet wrote:
>
> Hi All,
>>
>> I'm trying to add a map on the following lattice plot, but not
>> correctly...
>> can anyone help please...
>>
>> R Code:
>>
>> require(lattice)
>> us.map <- map(plot = FALSE, fill = TRUE)
>>
>
> Maybe you should explain why you think plotting quake locations near Fiji
> might show up on a map of the united States?
>
>  Depth <- equal.count(quakes$depth, number=8, overlap=.1)
>> xyplot(lat ~ long | Depth, data = quakes,
>>  panel = function(...) {
>>   panel.polygon(us.map$x,us.map$y)
>>   panel.xyplot(...)
>>  }
>> )
>>
>> Any help would be greatly appreciated,
>> Gurmeet
>>
>>[[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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[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.


[R] calling map() in xyplot()

2010-03-09 Thread Gurmeet
Hi All,

I'm trying to add a map on the following lattice plot, but not correctly...
can anyone help please...

R Code:

require(lattice)
us.map <- map(plot = FALSE, fill = TRUE)
Depth <- equal.count(quakes$depth, number=8, overlap=.1)
xyplot(lat ~ long | Depth, data = quakes,
  panel = function(...) {
panel.polygon(us.map$x,us.map$y)
panel.xyplot(...)
  }
)

Any help would be greatly appreciated,
Gurmeet

[[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.


Re: [R] title problem

2009-11-21 Thread Gurmeet
Hi Carol,

Try this

>  par(oma=c(2,2,2,2))
>  par(mfrow = c(1,2))
>  plot(c(1,2,3), c(9,8,7))
>  plot(c(1,2,3), c(9,8,7))
>  title(main = "Main title", sub ="Sub title",outer = TRUE, cex.main=1.5,
cex.sub = 1.5)

par(oma=c(2,2,2,2)) -- can be used to define outline of the plot. Arguments
here are for "bottom", "left", "top", "right"; which ofcourse can be changed
according to need. HTH

Gurmeet


On Sat, Nov 21, 2009 at 11:21 AM, carol white  wrote:

> Hi,
> I got problem in using title function to create a title for multiple plots
> presented together by par. As can be seen in the attached file, the title is
> displayed truncated and the subtitle doesn't get displayed. Here is the
> code:
>
>  par(mfrow = c(1,2))
>  plot(c(1,2,3), c(9,8,7))
>  plot(c(1,2,3), c(9,8,7))
>  title(main = "Main title", sub ="Sub title",outer = TRUE, cex.main=1.5,
> cex.sub = 1.5)
>
> Carol
>
>
>
> __
> 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]]

__
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.