basic plot of all independent variables and regression stats

31 views
Skip to first unread message

ian.shrier

unread,
Jan 24, 2010, 8:31:02 AM1/24/10
to ggplot2
I was recently told about ggplot and have been looking into it. I'm an
epidemiologist and not a statistician and just starting using R about
2 years ago.

I have two questions.

First, one of the first things I like to do is to simply plot out the
univariate distributions of each variable. For most of my studies,
this is easy as there are not that many variables and I do them one by
one. But I am now involved in a study with many many variables and I
just think there must be an easy way to do this in R. I was looking
through ggplot and know about facet_grid, but that seems to just
subset the data of one variable. I want to just have each panel as a
simple distribution. It would be the graphic equivalent of summary
(data.frame). Does ggplot do this? If not, do you know of another
package? I tried lattice but couldn't get that to work either.

Second, I like to print out the regression stats on my graphs. I
figured out how to plot the regression line on the graph (i used lm
but this should be applicable to anything), but I can't find anything
in the help file about printing out the actual r-squared, equation, p-
value, etc onto the graph. Now, I could just add text to the plot, but
I was thinking that if ggplot calculated the regression line, the
results have to be stored somewhere and are probably easy to include
with some option.

I tried the search feature in the discussion group but was
unsuccessful. Thanks for your help.

Ian

Mike Lawrence

unread,
Jan 24, 2010, 9:18:28 AM1/24/10
to ian.shrier, ggplot2
Not precisely what you're looking for, but you might want to check out
the "ezCor()" function in the "ez" package:
install.packages('ez',type='source')
library('ez')
?ezCor

See the example in the ezCor() help for demonstration for using it. If
you want something similar but different, see the source (simply type
'ezCor' at the prompt) to see how it was all put together.

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
>
>

--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

Nicholas Lewin-Koh

unread,
Jan 24, 2010, 1:39:31 PM1/24/10
to ian.shrier, ggplot2
Hi Ian,
If you have a large number of variables, where if you try to plot all
densities
it would take many pages, you should look at the Hmisc package.
for instance
> library(Hmisc)
> latex(describe(<your data.frame>))
will give you output to latex, and with pdflatex you get something like
this
http://biostat.mc.vanderbilt.edu/wiki/pub/Main/Hmisc/counties.pdf

Hope this helps
Nicholas

On Sun, 24 Jan 2010 05:31 -0800, "ian.shrier" <ian.s...@mcgill.ca>
wrote:

Nicholas Lewin-Koh

unread,
Jan 24, 2010, 6:49:29 PM1/24/10
to Ian Shrier, Dr., ggplot2
Hi,
You need to have a full (la)tex system installed. If you are on windows,
install miktex. If you are on a debian based linux system
sudo apt-get install texlive

On an rpm based linux system like fedora, probably something like
yum install texlive
but not sure

Mac: on your own ;)

The two packages should be part of texlive, and miktex has an automatic
package installer.

Hope this helps

Nicholas


On Sun, 24 Jan 2010 17:47 -0500, "Ian Shrier, Dr."
<ian.s...@mcgill.ca> wrote:
> Nicholas
>
> pretty neat function in the PDF. The describe function gave the data in
> text. I got an error when I tried the latex feature that superimposes the
> graphs:
>
> #######
> /bin/sh: latex: command not found
> sh: xdvi: command not found
> ######
>
> the help file says the following: "Note that the latex method assumes you
> have the following styles installed in your latex installation: setspace
> and relsize."
>
> How do I do this?
>
> Ian Shrier MD, PhD, Dip Sport Med, FACSM
> Associate Professor, Dep't of Fam Med, McGill University
> Past-President, Canadian Academy of Sport Medicine
> Check out: www.casm-acms.org<http://www.casm-acms.org>
> SKYPE name: ian.shrier
>
> Centre for Clinical Epidemiology and Community Studies
> SMBD-Jewish General Hospital
> 3755 Cote Ste-Catherine Rd
> Montreal, Qc H3T 1E2
> Tel: 514-340-7563
> Fax: 514-340-7564

Ian Shrier, Dr.

unread,
Jan 24, 2010, 5:47:28 PM1/24/10
to Nicholas Lewin-Koh, ggplot2
Nicholas

pretty neat function in the PDF. The describe function gave the data in text. I got an error when I tried the latex feature that superimposes the graphs:

#######
/bin/sh: latex: command not found
sh: xdvi: command not found
######

the help file says the following: "Note that the latex method assumes you have the following styles installed in your latex installation: setspace and relsize."

How do I do this?

Ian Shrier MD, PhD, Dip Sport Med, FACSM
Associate Professor, Dep't of Fam Med, McGill University
Past-President, Canadian Academy of Sport Medicine
Check out: www.casm-acms.org<http://www.casm-acms.org>
SKYPE name: ian.shrier

Centre for Clinical Epidemiology and Community Studies
SMBD-Jewish General Hospital
3755 Cote Ste-Catherine Rd
Montreal, Qc H3T 1E2
Tel: 514-340-7563
Fax: 514-340-7564

On 2010-01-24, at 1:39 PM, Nicholas Lewin-Koh wrote:

Brian Diggs

unread,
Jan 25, 2010, 1:55:44 PM1/25/10
to ggplot2

On Jan 24, 3:49 pm, "Nicholas Lewin-Koh" <ni...@hailmail.net> wrote:
> Hi,
> You need to have a full (la)tex system installed.
>

> Mac: on your own ;)

Just to complete your summary instructions, for Mac, MacTeX at
http://www.tug.org/mactex/2009/

--Brian Diggs

Reply all
Reply to author
Forward
0 new messages