Ternaryplot as an inset graph

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Ternaryplot as an inset graph

Young, Jennifer A
Hello

I am trying to add a ternary plot as a corner inset graph to a larger
main ternary plot. I have successfully used add.scatter in the past for
different kinds of plots but It doesn't seem to work for this particular
function. It overlays the old plot rather than plotting as an inset.

Here is a simple version of what I'm trying. Note that if I change the
inset plot to be an ordinary scatter, for instance, it works as
expected.

library(ade4)
library(vcd)
tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
insetPlot <- function(data){
  ternaryplot(data)
}
ternaryplot(tdat)
add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)

Thanks very much,

Jennifer Young
Fisheries and Oceans Canada
[hidden email]


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Ternaryplot as an inset graph

bbolker
Young, Jennifer A <Jennifer.Young <at> dfo-mpo.gc.ca> writes:

> I am trying to add a ternary plot as a corner inset graph to a larger
> main ternary plot. I have successfully used add.scatter in the past for
> different kinds of plots but It doesn't seem to work for this particular
> function. It overlays the old plot rather than plotting as an inset.
>
> Here is a simple version of what I'm trying. Note that if I change the
> inset plot to be an ordinary scatter, for instance, it works as
> expected.
>
> library(ade4)
> library(vcd)
> tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
> insetPlot <- function(data){
>   ternaryplot(data)
> }
> ternaryplot(tdat)
> add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)
>

  I think the problem is that add.scatter assumes you're using base
graphics, while ternaryplot() uses grid graphics.  Mixing and
matching grid+base graphs is a little bit tricky.  You might try it with
triax.plot() from the plotrix package, which I believe does ternary
plots in base graphics ...

  Ben Bolker

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Ternaryplot as an inset graph

glsnow
The triplot function in the TeachingDemos package uses base graphics,
the subplot function (also in TeachingDemos) is another way to place a
plot within a plot (and triplot and subplot do work together).

If you want to stick to grid graphics then you can use viewports in
grid to insert one plot into another.

On Fri, Apr 20, 2012 at 10:05 AM, Ben Bolker <[hidden email]> wrote:

> Young, Jennifer A <Jennifer.Young <at> dfo-mpo.gc.ca> writes:
>
>> I am trying to add a ternary plot as a corner inset graph to a larger
>> main ternary plot. I have successfully used add.scatter in the past for
>> different kinds of plots but It doesn't seem to work for this particular
>> function. It overlays the old plot rather than plotting as an inset.
>>
>> Here is a simple version of what I'm trying. Note that if I change the
>> inset plot to be an ordinary scatter, for instance, it works as
>> expected.
>>
>> library(ade4)
>> library(vcd)
>> tdat <- data.frame(x=runif(20), y=rlnorm(20), z=rlnorm(20))
>> insetPlot <- function(data){
>>   ternaryplot(data)
>> }
>> ternaryplot(tdat)
>> add.scatter(insetPlot(tdat), posi="topleft", ratio=.2)
>>
>
>  I think the problem is that add.scatter assumes you're using base
> graphics, while ternaryplot() uses grid graphics.  Mixing and
> matching grid+base graphs is a little bit tricky.  You might try it with
> triax.plot() from the plotrix package, which I believe does ternary
> plots in base graphics ...
>
>  Ben Bolker
>
> ______________________________________________
> [hidden email] 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.



--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] 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.