# [R] [External] Package for "design graphs"

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Thu Aug 19 02:22:35 CEST 2021

```Thank you for the example.

Here is a simple function in base graphics that does what you ask for.

You can turn off the default borders and ticks and tick labels and xlab and ylab,
and add your own x tick labels, and then it will look exactly like the example you sent.

Rich

expt1 <- data.frame(from=c(1,1,2,2,3,3,4,4),
to=c("A","B","A","B","C","D","C","D"))

expt2 <-  data.frame(from=c(1,1,2,2,3,3,4,4),
to=c("A","B","B","C","C","D","D","A"))

DesignGraph <- function(x, pch.from=19, pch.to=19) {
from <- unique(x\$from)
to <- unique(x\$to)

n.from <- length(from)
n.to <- length(to)
Nrows<- max(1:n.from, 1:n.to)

plot(1 ~ 1, type="n", xlim=c(1-.5, 2+.5), ylim=c(Nrows, 1))

points(x=rep(1, n.from), y=1:n.from, pch=pch.from)
text(x=1-.3, y=1:n.from, labels=from)

points(x=rep(2, n.to), y=1:n.to, pch=pch.to)
text(x=2+.3, y=1:n.to, labels=to)

index.from <- which
index.to <- which

segments(1, match(x\$from, from), 2, match(x\$to, to))
}

DesignGraph(expt1)

DesignGraph(expt2)

> On Aug 18, 2021, at 10:29, madsmh using gmail.com wrote:
>
> I have attached a photo from our book
>
> E. Hansen "Introduktion til matematisk statistik"
>
> the numbers represent the labels of one factor while the letters
> represent the labels of anothr factor.
>
>
>
> On Tue, 2021-08-17 at 22:42 +0000, Richard M. Heiberger wrote:
>> can you post an example of the graph?
>>
>> From: R-help <r-help-bounces using r-project.org> on behalf of
>> madsmh using gmail.com <madsmh using gmail.com>
>> Sent: Tuesday, August 17, 2021 16:02
>> To: r-help using r-project.org
>> Subject: [External] [R] Package for "design graphs"
>>
>> Hi,
>>
>> in our course littrature a "design graph" of two factors R and S with
>> associated maps s : I -> S and f : I -> S where I is some finite
>> index
>> set, is a graph with factor labeles as vertices and lines f(i) to
>> s(i)
>> for all observations i in I. Is there a package on CRAN that can draw
>> graphs like this automatically?
>>
>> I haven't been able to find anyting by searching.
>>