4

I have a question on creating a dotchart using the following data:

    Patient ID Day Dosage of Drug (mg)
     1552        1     .3
     1552        7     .8
     1552       14    1.2
     1663        1     .2
     1663        7     .7
     1663       18    1.4

I can create the dotchart with the x-axis as "day" and y-axis as each patient so that for Patient ID 1552, there are three points at days 1, 7, and 14. No problems there. But now I want to make it so that the dot sizes are proportional to the amount of dosage taken on that day so that the dot on day 14 will be larger than 7 and 1 on the same Patient ID line. Is there any way I can do this?

I know the dotchart() function has a modifiable cex element that changes the y-axis font/dot size but it does so uniformly. Is there any way of plotting each point separately and each time making the dot size a different size according to the Dose data?

Andrey
  • 2,503
  • 3
  • 30
  • 39
JohnLu
  • 41
  • 2

2 Answers2

1

I would create such a chart using ggplot2:

ggplot(aes(x = day, y = patient, size = dosage), data = df) + 
      geom_point()

Where I assume the data.frame with the data is called df, and that it contains the columns named day, patient, and dosage.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
  • oh man, that worked great. I modified the ggplot slightly after taking a look at a ggplot tutorial and went with geom_point(aes(size = dosage)). Thanks a lot! – JohnLu Jun 13 '12 at 14:11
  • 1
    Mind ticking an answer as the correct answer? That way people get some reputation, and everyone can see your problem is solved. – Paul Hiemstra Jun 13 '12 at 15:51
1

If you use the ggplot2 package, you can do it like this:

dat <- read.table(textConnection("ID Day Dose
     1552        1     .3
     1552        7     .8
     1552       14    1.2
     1663        1     .2
     1663        7     .7
     1663       18    1.4"), header=TRUE)    

require(ggplot2)
p <- ggplot(dat, aes(factor(Day), factor(ID)))
p + geom_dotplot(binaxis = "y", stackdir = "center", binpositions="all") + 
 geom_point(aes(size=Dose))

enter image description here

smillig
  • 5,073
  • 6
  • 36
  • 46