[R] Create Dot Chart

Joshua Wiley jwiley.psych at gmail.com
Sun Sep 19 17:46:08 CEST 2010


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 <AVSHALO2 at 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 at 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/



More information about the R-help mailing list