Re: [R] Create Dot Chart

2010-09-19 Thread Joshua Wiley
Hi,

Here are three examples for something along those lines.  The first
uses the package lattice, 2 and 3 use ggplot2.  There are lots of
options, and you can tweak and customize these to your hearts content.

dat - data.frame(group = factor(rep(0:1, each = 40), labels =
c(Control, Treatment)),
  id = rep(1:20, each = 4),
  days = sample(1:120, 80, replace = TRUE)
  )

library(lattice)

## Example 1 ##
dotplot(x = id ~ days, data = dat, group = group, auto.key = TRUE)

library(ggplot2)

## Example 2 ##
ggplot(data = dat, aes(x = days, y = id, colour = group)) +
  geom_point() +
  scale_y_continuous(breaks = unique(dat$id))

## Example 3 ##
ggplot(data = dat, aes(x = days, y = id)) + geom_point() +
  facet_grid(group ~ ., scales = free) +
  scale_y_continuous(breaks = unique(dat$id))


Hope that helps,

Josh

On Sun, Sep 19, 2010 at 7:46 AM, avsha38 avsha...@post.tau.ac.il wrote:

 Hello everyone...

 I would like to create a chart (see below), how can I do it with R?

 Any help, suggestion, samples... will be greatly appreciated.

 Thanks... Avi

 http://r.789695.n4.nabble.com/file/n2545921/DotChart.jpg
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2545921.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread John Kane
?dotchart perhaps.

--- On Sun, 9/19/10, avsha38 avsha...@post.tau.ac.il wrote:

 From: avsha38 avsha...@post.tau.ac.il
 Subject: [R] Create Dot Chart
 To: r-help@r-project.org
 Received: Sunday, September 19, 2010, 10:46 AM
 
 Hello everyone...
 
 I would like to create a chart (see below), how can I do it
 with R?
 
 Any help, suggestion, samples... will be greatly
 appreciated.
 
 Thanks... Avi
 
 http://r.789695.n4.nabble.com/file/n2545921/DotChart.jpg
 
 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2545921.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org
 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.


__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread avsha38

Hi Josh,

Great samples! Thanks a lot!
I ran your code and saw the Dot Chart, looks like what I need.

I would like to ask for your help with applying it to my file,
coming from the Theoretical world making it tough for me to apply in the
Code..
attached below is part of my dataset
num1 is ID variable
Grouping variable = ESHKOL_tert (factor with 3 levels: 1-3)
T1 - T4 are the recurrent events (time in months from index for each
subject)

http://r.789695.n4.nabble.com/file/n2546019/recmi_dots.jpg 

thanks in advance,
Avi
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2546019.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread David Winsemius


On Sep 19, 2010, at 12:58 PM, avsha38 wrote:



Hi Josh,

Great samples! Thanks a lot!
I ran your code and saw the Dot Chart, looks like what I need.

I would like to ask for your help with applying it to my file,
coming from the Theoretical world making it tough for me to apply in  
the

Code..
attached below is part of my dataset


I'm afraid not. If you had read the Posting Guide, (please do so now),  
you should have noted that only text files (with file extensions  
of .txt) will be accepted by the mail-server. You can follow the  
directions of the Posting Guide or you can paste in the output of  
dput() around you data.frame or matrix.





num1 is ID variable
Grouping variable = ESHKOL_tert (factor with 3 levels: 1-3)
T1 - T4 are the recurrent events (time in months from index for each
subject)

http://r.789695.n4.nabble.com/file/n2546019/recmi_dots.jpg

thanks in advance,
Avi


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread avsha38

Hi Josh, 

Great samples! Thanks a lot! 
I ran your code and saw the Dot Chart, looks like what I need. 

I would like to ask for your help with applying it to my file, 
coming from the Theoretical world making it tough for me to apply in the
Code.. 
attached below is part of my dataset 
num1 is ID variable 
Grouping variable = ESHKOL_tert (factor with 3 levels: 1-3) 
T1 - T4 are the recurrent events (time in months from index for each
subject) 
http://r.789695.n4.nabble.com/file/n2546047/recmi.txt recmi.txt 
thanks in advance,
Avi
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2546047.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread David Winsemius


On Sep 19, 2010, at 1:49 PM, avsha38 wrote:



Hi Josh,

Great samples! Thanks a lot!
I ran your code and saw the Dot Chart, looks like what I need.

I would like to ask for your help with applying it to my file,
coming from the Theoretical world making it tough for me to apply in  
the

Code..


Then it's time to move away from the chalkboard and get practical at  
the keyboard. Start with the R Data Import/Export Manual which is  
mentioned and linked in the Further Resources section of the Posting  
Guide.


Because of the irregular line length, your data needs the facilities  
provided by the fill argument to read.table(). You will them probably  
need to choose between learning the reshape function (not the easiest  
task) or the melt/cast combination in the reshape2 package. There are  
worked examples on the help pages and many more in the rhelp archives.




attached below is part of my dataset
num1 is ID variable
Grouping variable = ESHKOL_tert (factor with 3 levels: 1-3)
T1 - T4 are the recurrent events (time in months from index for each
subject)
http://r.789695.n4.nabble.com/file/n2546047/recmi.txt recmi.txt
thanks in advance,
Avi
--


--
David.

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread Joshua Wiley
Ahoy Avi,

Sounds like you be wantin' a gander more explanation than 'til you get
your Arrr legs.

# Read in data
# I chose to specify explicit classes because the ids and ESHKOL_tert
# are really categorical data, so I made them factors
# also your data was tab delimited, which I specified using the sep = \t
dat - read.table(http://r.789695.n4.nabble.com/file/n2546047/recmi.txt;,
  header = TRUE, sep = \t,
  colClasses = c(factor, factor, rep(integer, 4))
  )

# look at the STRucture of the newly created object
# notice the first two things are factors
# and the rest are 'int' or integer class
str(dat)

# load the reshape package for the melt function
# I find this function easier to demonstrate with than
# the reshape() function itself that David mentioned
library(reshape)

# reshape the data into a more amenable form
# I am being explicit in this call, generally
# one would do something much simpler: melt(dat, 1:2) would work
dat2 - melt(data = dat, id.vars = c(num1, ESHKOL_tert),
 measure.vars = c(T1, T2, T3, T4),
 variable_name = times)

# melt() calls this form molten, many people refer to it as
# 'long' versus 'wide'
# traditionally, 'wide' data has one row per person/thing
# 'long' data has one row per time point
# since you had T1 - T4, each id now gets 4 rows
# so the table will be four times as long, checking this:
nrow(dat2) == 4 * nrow(dat)

# load the ggplot2 package to make the graph
library(ggplot2)

# Creating the actual graph
ggplot(data = dat2, aes(x = value, y = num1)) +
  geom_point() +
  facet_grid(ESHKOL_tert ~ ., scales = free)

# This may seem complicated, but it is fairly straightforward
# ggplot() creates sort of the base of the graphic
# it defines what the dataset is and what goes on the X and Y axes
# geom_point() adds points to the graph, I could just as easily have used
# geom_line() to get lines, etc.
# facet_grid() facets the data by level of ESHKOL_tert (so you get 3 panels)
# You might prefer the 'quick' way of plotting using ggplot2

qplot(x = value, y = num1, data = dat2, geom = point) +
  facet_grid(ESHKOL_tert ~ ., scales = free)

# for further reading

?read.table # this is how we read the data in
?str # I cannot recommend this function enough
# Assuming the reshape package is loaded
?melt
# or for this particular case
?melt.data.frame
# for the graph parts
?ggplot
?qplot


You can also go to Hadley's website:
http://had.co.nz/ggplot2/

He has a book to which I recommend if you will be using ggplot2 a lot.
 Speaking of books, the R website has a list of books on R, and there
are a lot of really nice introductory ones there.
http://www.r-project.org/doc/bib/R-books.html

You can also find and learn a lot online and through the documentation
(like I showed above).

I am not really sure how you wanted to show time, id, the actual
values, and group (ESHKOL) in one plot.  So I did not do anything with
time (T1 - T4).

Cheers,

Makes-a-terrible-pirate-Josh

On Sun, Sep 19, 2010 at 10:49 AM, avsha38 avsha...@post.tau.ac.il wrote:

 Hi Josh,

 Great samples! Thanks a lot!
 I ran your code and saw the Dot Chart, looks like what I need.

 I would like to ask for your help with applying it to my file,
 coming from the Theoretical world making it tough for me to apply in the
 Code..
 attached below is part of my dataset
 num1 is ID variable
 Grouping variable = ESHKOL_tert (factor with 3 levels: 1-3)
 T1 - T4 are the recurrent events (time in months from index for each
 subject)
 http://r.789695.n4.nabble.com/file/n2546047/recmi.txt recmi.txt
 thanks in advance,
 Avi
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2546047.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread avsha38

Hi Josh 

Wow, I greatly appreciate you taking the time to help out. It works
excellent!!!
I am just a beginner with R; thanks a lot for your books recommendation, I
will be using them.

If I may ask you, I have about 300 records in the full file and once I ran
the code with the full file,
The values on the Y axis are not showing properly, as they overlap each
other. 
Do you have any suggestion for solving that?

Thanks again,
Avi

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2546250.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org 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.


Re: [R] Create Dot Chart

2010-09-19 Thread Dennis Murphy
Hi:

It seems to me that num1 is a nested factor within ESHKOL_tert. With that in
mind, I redefined the two terms to be factors and redid Josh's plot as
follows:

dat3 - dat2
dat3 - transform(dat3, num1 = factor(num1), ESHKOL_tert =
factor(ESHKOL_tert))
ggplot(data = dat3, aes(x = value, y = num1)) +
geom_point() +
facet_grid(ESHKOL_tert ~ ., scales = free)

This yields a different appearance, showing that most of the num1 levels are
in ESHKOL_tert 2, but the concept is the same. I like how ggplot2 'knows'
about the nesting relationship. To see this, go into the original data frame
dat and type

with(dat, table(num1, ESHKOL_tert))

If you find that the values on the y-axis overlap each other, add (+) the
following line to your ggplot() code:

opts(axis.text.y = theme_text(size = 7))

If it's too large, lower the number, and vice versa.

HTH,
Dennis


On Sun, Sep 19, 2010 at 2:21 PM, avsha38 avsha...@post.tau.ac.il wrote:


 Hi Josh

 Wow, I greatly appreciate you taking the time to help out. It works
 excellent!!!
 I am just a beginner with R; thanks a lot for your books recommendation, I
 will be using them.

 If I may ask you, I have about 300 records in the full file and once I ran
 the code with the full file,
 The values on the Y axis are not showing properly, as they overlap each
 other.
 Do you have any suggestion for solving that?

 Thanks again,
 Avi

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Create-Dot-Chart-tp2545921p2546250.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.