ggpairs with lines instead of points

682 views
Skip to first unread message

Neuwirth Erich

unread,
Jul 2, 2012, 5:47:25 AM7/2/12
to ggp...@googlegroups.com
Is there a way to tell ggpairs to plot lines instead of points?

Brandon Hurr

unread,
Jul 2, 2012, 7:02:15 AM7/2/12
to Neuwirth Erich, ggp...@googlegroups.com
I'm sure you could hack the function to do so... what exactly do you want the lines to go between?

The scatterplot points are unique individuals. In your data are there groups or timepoints that you need to connect in some way? 

Do you have an example dataset to work with? Use dput() if possible. 

Brandon

On Mon, Jul 2, 2012 at 10:47 AM, Neuwirth Erich <erich.n...@univie.ac.at> wrote:
Is there a way to tell ggpairs to plot lines instead of points?

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Neuwirth Erich

unread,
Jul 2, 2012, 7:15:49 AM7/2/12
to ggp...@googlegroups.com
I have ecg data, so the data are time series.
There is a natural ordering, therefore I want th points to be connected in sequence.
geom_path in ggplot does what I want for plots of 2 variables. I need the same thing for ggpairs.



On Jul 2, 2012, at 11:47 AM, Neuwirth Erich wrote:

> Is there a way to tell ggpairs to plot lines instead of points?
>

Brandon Hurr

unread,
Jul 2, 2012, 8:11:52 AM7/2/12
to Neuwirth Erich, ggp...@googlegroups.com
I'm still a little confused about what you actually want. In the panels of the attached plot, which panels would have your time axis (e.g. [3,1])? And, what do you expect those panels to look like? 

Brandon
Rplot001.png

Neuwirth Erich

unread,
Jul 2, 2012, 11:32:35 AM7/2/12
to ggp...@googlegroups.com
This is an example of what I would like to see in each of the facets.


   x<-2*pi*seq(0,1,0.01)
   plot(sin(x),cos(x),type="l")

Brandon Hurr

unread,
Jul 2, 2012, 3:42:44 PM7/2/12
to Neuwirth Erich, ggp...@googlegroups.com
It ain't perfect, but attached is what I came up with. I'm not very skilled when it comes to making my scripts succinct and efficient though...

This could be tweaked much further to get what you want. Perhaps, others have a better way of doing it? Or could help clean up my code?

B

grid play.R

Dennis Murphy

unread,
Jul 2, 2012, 4:17:50 PM7/2/12
to Neuwirth Erich, ggp...@googlegroups.com
Hi:

I'm wondering why you want to use ggpairs() from the GGally package
rather than facet_wrap() or facet_grid() in ggplot2, but perhaps the
last example on the ggpairs() help page (the one involving the custom
plot and use of the putPlot() function) might serve the purpose. As an
alternative, I wonder if an example posted in this group last year by
Baptiste Auguie
http://groups.google.com/group/ggplot2/browse_thread/thread/a3815562ed999efd/fd8ba56adac4b35f?lnk=gst&q=Baptiste+spectra#fd8ba56adac4b35f

might be appropriate for your needs. If neither of these suggestions
are helpful and Brandon's yeoman effort isn't what you had in mind, a
reproducible example would be useful.

Dennis

Neuwirth Erich

unread,
Jul 3, 2012, 6:04:27 AM7/3/12
to ggp...@googlegroups.com
This is the simplified equivalent of what ggpairs does.


myt <- seq(0,1,0.01)*2*pi
mydf <- data.frame(
          myt = myt,
          x1 = sin(myt),
          x2 = sin(myt+0.05),
          x3 = sin(myt+pi/8),
          x4 =  cos(myt)
   
par(mfrow=c(4,4))
for (i in 1:4)
  for (j in 1:4)
    plot(mydf[,i],mydf[,j])


I would like to have

par(mfrow=c(4,4))
for (i in 1:4)
  for (j in 1:4)
    plot(mydf[,i],mydf[,j],type="l")


I think the data also illustrate why I would rather have lines than points.






Brandon Hurr

unread,
Jul 3, 2012, 7:02:39 AM7/3/12
to Neuwirth Erich, ggp...@googlegroups.com
We can do this with my code, but I can't get to it until much later today or later this week. :|

Neuwirth Erich

unread,
Jul 5, 2012, 8:53:59 AM7/5/12
to Brandon Hurr, ggp...@googlegroups.com
I am extending my wish list ;-)
I need either a way to user a smaller font in the title or an option to print a title with 2 lines or title + subtitle.
I have to put more information in the title.
Is there a way of doing this already?

Brandon Hurr

unread,
Jul 5, 2012, 9:16:13 AM7/5/12
to Neuwirth Erich, ggp...@googlegroups.com
Have we got the other parts right yet? 

If you only want lines like your recent example, change geom_point() to geom_line(group=1) in the file I sent. 

As far as a title + subtitle... I'll think about it, it's not so easy methinks. 

Neuwirth Erich

unread,
Jul 6, 2012, 2:44:26 AM7/6/12
to Brandon Hurr, ggp...@googlegroups.com
I still do not know enough about the internals of the functions, but I think a clean solution for my problem would be if the
upper and lower parameters of ggairs also could accepts something line

upper = list(continuous = "lines")
instead of
upper = list(continuous = "points")

To me this seems the most natural interface for what I need.

Dianne Cook

unread,
Jul 6, 2012, 3:26:27 AM7/6/12
to Neuwirth Erich, Brandon Hurr, ggp...@googlegroups.com
Erich and Brandon and Dennis,

Sorry, I missed your initial post on ggpairs. All you need to do is basically create a new function that mimics the points function:

ggally_points <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + geom_point(...)
  p$type <- "continuous"
  p$subType <- "points"
  p
}

I can add a function to the ggally package to draw lines.

cheers,
Di

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---------------------------
Di Cook




Neuwirth Erich

unread,
Jul 6, 2012, 5:38:09 AM7/6/12
to Dianne Cook, Brandon Hurr, ggp...@googlegroups.com
Here is another problem.
I need ti display 13 variables.


myt <- seq(0,1,0.01)*2*pi
mydf <- data.frame(
myt = myt,
x1 = sin(myt),
x2 = sin(myt+0.05),
x3 = sin(myt+pi/8),
x4 = cos(myt),
x5 = sin(myt),
x6 = sin(myt+0.05),
x7 = sin(myt+pi/8),
x8 = cos(myt),
x9 = sin(myt),
x10 = sin(myt+0.05),
x11= sin(myt+pi/8),
x12 =cos(myt))


ggpairs(mydf,upper=list(continuous="points"))
ggpairs(mydf,upper=list(continuous="points"),params=c(cex=0.25))
ggpairs(mydf,upper=list(continuous="points"),params=c(cex=0.25,cex.axis=0.25))


As the second charts shows, cex rescues the point size.
But cex.axis is useless in the last chart.
I need to make the variable label and the axis annotations in the diagonal facets smaller.
Is there a way to accomplish this?

Neuwirth Erich

unread,
Jul 6, 2012, 10:59:30 AM7/6/12
to Dianne Cook, Brandon Hurr, ggp...@googlegroups.com
I played around and found the solution.
I need geom_path instead of geom_point.

Di, could you please add such a function.

ggally_path <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + geom_path(...)
  p$type <- "continuous"
  p$subType <- "path"
  p
}

Neuwirth Erich

unread,
Jul 6, 2012, 11:37:01 AM7/6/12
to Dianne Cook, Brandon Hurr, ggp...@googlegroups.com
This is an example of how it works and why it makes sense.

library(GGally)
myt <- seq(0,1,0.01)*2*pi
mydf <- data.frame(
         myt = myt,
         x1 = sin(myt),
         x2 = sin(myt+0.05),
         x3 = sin(myt+pi/8),
         x4 =  cos(myt))



ggally_path <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + geom_path(...)
  p$type <- "continuous"
  p$subType <- "path"
  p
}




ggpairs(mydfsmall,lower=list(continuous="points"),
        upper=list(continuous="points"))

ggpairs(mydfsmall,lower=list(continuous="path"),
        upper=list(continuous="path"))


On Jul 6, 2012, at 9:26 AM, Dianne Cook wrote:

Brandon Hurr

unread,
Jul 6, 2012, 1:00:17 PM7/6/12
to Neuwirth Erich, Dianne Cook, ggp...@googlegroups.com
I'm glad you figured it out. I got a little lost when I looked at the ggpairs() function and just "yeomaned" it, as Dennis said. 

I'm still not sure how to do the Title/Subtitle thing though. Probably the easiest thing would be to export it and edit in Inkscape, since I think you'll end up having to hack GGally hard to get that wish.

Neuwirth Erich

unread,
Jul 6, 2012, 1:00:36 PM7/6/12
to Dianne Cook, Brandon Hurr, ggp...@googlegroups.com
I am a pest, I know.
But I really really need a way to either produce a two line title or to add a footer line to the ggpairs graph.
If there is a way to use a smaller font for the title, I might be able to produce a two line title.
In fact, a two line title works, but then the second line is overprinted with the charts.
So if I could use a smaller font, I might be able to display 2 lines in the title area.


Brandon Hurr

unread,
Jul 6, 2012, 1:20:57 PM7/6/12
to Neuwirth Erich, Dianne Cook, ggp...@googlegroups.com
Baptiste helped me ages ago trying to get multiple lines in the title. 

I don't know if you can do different font sizes with this though. I think everything has to be the same size, but Baptiste suggested that you could create a subtitle function as well... 

Also, you're not a pest, this exercise has been educational and you may have helped adapt GGally to a new situation. 

B

Dianne Cook

unread,
Jul 6, 2012, 8:07:28 PM7/6/12
to Neuwirth Erich, Brandon Hurr, ggp...@googlegroups.com
Erich,

A new version of GGally with both path and lines options is ready to ftp to CRAN. It seems that the CRAN machines are down right now so will try again later today. 

Haven't checked the two line title possibility yet. Will do that next.

cheers,
Di
---------------------------
Di Cook




Reply all
Reply to author
Forward
0 new messages