Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can change the vertical location of the label according to the numeric value of Visit.</p> <p>The key is:</p> <pre><code> y=(as.numeric(Patient)+0.25*as.numeric(Visit)%%3)-0.12 </code></pre> <p>This currently produces:<br> 3 different levels according to values of Visit (%%3), which you can increase or decrease<br> each level is separated by a quarter of the distance between y labels (0.25)<br> the first label is 0.12 below the horizontal line<br> the second is 0.12 above</p> <p><img src="https://i.stack.imgur.com/Ljqqb.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/tY5kL.jpg" alt="enter image description here"></p> <pre><code>require(ggplot2) require(plyr) require(reshape) # create sample data set.seed(666) dfn &lt;- data.frame( Referral = seq(as.Date("2007-01-15"), len= 26, by="23 day"), VISIT01 = seq(as.Date("2008-06-15"), len= 24, by="15 day")[sample(30, 26)], VISIT02 = seq(as.Date("2008-12-15"), len= 24, by="15 day")[sample(30, 26)], VISIT03 = seq(as.Date("2009-01-01"), len= 24, by="15 day")[sample(30, 26)], VISIT04 = seq(as.Date("2009-03-30"), len= 24, by="60 day")[sample(30, 26)], VISIT05 = seq(as.Date("2010-11-30"), len= 24, by="6 day")[sample(30, 26)], VISIT06 = seq(as.Date("2011-01-30"), len= 24, by="6 day")[sample(30, 26)], Discharge = seq(as.Date("2012-03-30"), len= 24, by="30 day")[sample(30, 26)], Patient = factor(1:26, labels = LETTERS), openCase = rep(0:1, 100)[sample(100, 26)]) # set today's data for cases that do not have an Discharge date dfn$Discharge[ is.na(dfn$Discharge) ] &lt;- as.Date("2014-01-30") mdfn &lt;- melt(dfn, id=c('Patient', 'openCase'), variable_name = "Visit") names(mdfn)[4] &lt;- 'Year' # rename # order data in mdfn by 'Referral' in dfn mdfn$Patient &lt;- factor(mdfn$Patient,levels = (dfn$Patient[order(dfn$Referral)]),ordered = TRUE) # subset a dataset to avoid 'Discharge' for cases that are not closed mdfn2 &lt;- subset(mdfn,!(Visit=="Discharge" &amp; Year &gt; as.Date("2014-01-01"))) # the plot as it looks now ggplot(mdfn, aes(Year, Patient)) + geom_blank() + geom_line(data = mdfn[mdfn$openCase == 0,], colour = "black") + geom_line(data = mdfn[mdfn$openCase == 1,], colour = "grey") + geom_point(data = mdfn2, aes(colour = Visit), size = 4, shape = 124) + geom_text(data=mdfn2, mapping=aes(x=Year, y=(as.numeric(Patient)+0.25*as.numeric(Visit)%%3)-0.12, label=substr(Visit, 1, 7), colour=Visit), size=2, hjust=-.1, angle = 00) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload