[R] Fwd: Question about paired plotting

Duncan Mackay dulcalma at bigpond.com
Tue May 5 01:06:07 CEST 2015


Hi 

With R there are usually several ways

Here is another one using lattice (I think it ships with R otherwise
install)

Reshape dat1 to long form and add a column for groups do give d2

d2 = structure(list(y = c(5L, 10L, 6L, 11L, 7L, 12L, 8L, 13L), x = c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L), gp = structure(c(1L, 1L, 2L, 2L,
3L, 3L, 4L, 4L), .Label = c("1", "2", "3", "4"), class = "factor")), .Names
= c("y",
"x", "gp"), row.names = c(NA, -8L), class = "data.frame")

library(lattice)


d2

library(lattice)

xyplot(y~x, data = d2,
       groups = gp,
       scales = list(x = list(at = 1:2,
                     labels= LETTERS[1:2])),
       col = 1,
       type = "b")

PS it makes it easier for every one if you send an example; even better
using dput
For windows 
dput(d2, file= "clipboard")
and paste it into your email

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au



-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Luis
Fernando García
Sent: Tuesday, 5 May 2015 04:35
To: John Kane
Cc: r-help at r-project.org
Subject: Re: [R] Fwd: Question about paired plotting

Dear John and Tim!

Thanks a lot for your replies. This is just what I needed!!

All the best for you!!

2015-05-04 13:58 GMT-03:00 John Kane <jrkrideau at inbox.com>:

> Hi Luis,
> Ah yes, that paper.  I was rather shocked at what it implied :(  People
> are still using dynamite plots, for heaven's sake! See
> http://biostat.mc.vanderbilt.edu/wiki/Main/DynamitePlots  for some
> comments.
> I see Jim has given you one way to do the plots you want. Here is another
> way using the ggplot2 package. You will probably have to install the
> package.  The code below covers the 2B:2D plots.
> ####=======Install ggplot2===================
> install.packages("ggplot2")
>
> ###======== plot desired graphs==================
> library(ggplot2)
>
> dat1  <-  data.frame(x1  = rep("A", 4) , x2  =  rep("B", 4), y1  =  5:8,
> y2  = 10:13)
>
> p  <-  ggplot()
> p1  <-   p +  geom_segment( aes(x = x1, y = y1, xend =  x2,  yend = y2)) +
>           geom_point(aes(x1, y1, colour = "blue", size = 2)) +
>           geom_point(aes(x2, y2, colour = "red", size = 2))
> p1
>
>  p2  <-     p1 +     theme (legend.position = "none") +
>                   xlab("Treatment") + ylab("Change Score")
> p2
>
> ###======== end==================
>
> We could have all the commands in one statement but it is easier to write
> the code this way to help in debugging (damn typos1) and so I left it to
> help you see what is happening.
>
> For the lower plots, in ggplot2, you should have a look at geom_dotplot()
> . Here is an interesting demo of it in use.  I like the addition of the
> median line in particular.
>
>
>
http://rstudio-pubs-static.s3.amazonaws.com/1406_947a49f2d7914dad8b0fd050a9d
f9858.html
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: luysgarcia at gmail.com
> > Sent: Mon, 4 May 2015 04:52:51 -0300
> > To: r-help at r-project.org
> > Subject: [R] Fwd: Question about paired plotting
> >
> > Hello R experts,
> >
> > I just found a new paper which shows the proper way (according to the
> > authors) to show data, specially paired. I am very interested in
> > presenting
> > this kind of data, specially the scatter plott.  I have found a way to
> > present it using this link:
> >
> >
>
http://journals.plos.org/plosbiology/article?id=10.1371%2Fjournal.pbio.10021
28#pbio.1002128.s007
> >
> > Nevertheless, I wanted to know if you know some example which allows me
> > to
> > produce a plot similar to the plots 2B-2D. I could do it by "hand" but
it
> > was quite time consuming and required editing the pictures,
> >
> > Many thanks for any help you can provide!
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> ____________________________________________________________
> FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
> Check it out at http://www.inbox.com/earth
>
>
>

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.



More information about the R-help mailing list