I could get the medians of each group and add this a new column by using the ddply and transform, but couldn't make it to have divisions of each marker reading by the corresponding V1 median. Any help? please try to find a flexible and short code for this purpose.
df<- ddply(df, c("group","site"), transform, marker.based=marker/marker.median[visit=="V1"])
Another question would be to combine the four medians together to establish a start point common to ALL four groups(in the graph you can see 4 different starting points for each group) so how can one make it only one start point for all?
Other question how to anchor this starting point to the lower left corner of the four plots, any idea?
scale_y_continuous(name="Marker normalized to V1",trans = 'log10', expand= c(0,0))
I've never used it before though so you'll have to tinker to get it right.
plot<-ggplot(df,aes(x=visit, y = as.numeric(marker.based), alpha=subject, shape=bacteria,group = subject),na.rm=TRUE) +
geom_point(size=4)+
geom_line(size=1) +
facet_grid(facets = site~group) +
scale_y_continuous(name="Marker normalized to V1",trans = 'log10')+
scale_shape_manual(name="Bacterial status",guide = guide_legend(),values = c(19,15))+
scale_alpha(guide = c(pos = 'none'))+
theme_bw()+
opts(axis.title.x = theme_blank(),axis.title.y = theme_text(size = 14.0,angle = 90.0),strip.text.x = theme_text(face = 'bold',size = 16.0),strip.text.y = theme_text(face = 'bold',size = 16.0,angle = 270.0))
plot
The attached dataset is a classical vaccine/placebo trial on 34 subjects. There are five visits (V1 >to V5) and I want to stratify readings of the marker measured in lab by site (A and C), and >bacteria (Positiv and Negative) at least for this example. I want to have my visit >readings(V2,V3,V4,V5) REFERENCED to the MEDIAN of the V1 readings within the stratified groups. So >the data if stratified should look like this. Let's go back to the problem: we agree that this line:
Vaccine/Placebo Site Bacteria Visits Marker
Vaccine A Positive V1, V2, V3, V4, V5
Vaccine A Negative V1, V2, V3, V4, V5
Vaccine C Positive V1, V2, V3, V4, V5
Vaccine C Negative V1, V2, V3, V4, V5
Placebo A Positive V1, V2, V3, V4, V5
Placebo A Negative V1, V2, V3, V4, V5
Placebo C Positive V1, V2, V3, V4, V5
Placebo C Negative V1, V2, V3, V4, V5
>So the first task is to stratify the dataset, then find the medians of V1 within each group >stratified (there can be different ways to stratify so the code better to take this into account >and be flexible), then find a way to divide the marker readings of other visits to that of V1 >median of the CORRESPONDING subgroup.
>I like to work with the R, plyr package, reshape or reshape2, and graphics with ggplot2.
>The first attahced file is dataset only, the second attached file is what I have done but manually >(time consuming to find out the reference V1 of the corresponding group for each reading). The graph is what the result should look like( see attached). I could get the medians of each group and add this a new column by using the ddply and transform, but couldn't make it to have divisions of each marker reading by the corresponding V1 median. Any help? please try to find a flexible and short code for this purpose. Another question would be to combine the four medians together to establish a start point common to ALL four groups(in the graph you can see 4 different starting points for each group) so how can one make it only one start point for all? Other question how to anchor this starting point to the lower left corner of the four plots, any idea? many thanks in advance.
and the trial_dataset_shouldbe.csv dataset where the last two columns were not in the first dataset, but done manually.
df<-ddply(df, c("group","site","visit"), transform,marker.median=median(as.numeric(marker),na.rm=TRUE),na.rm=T) # only this was done automatically the other column marker.based was done manually. I want to find a code for its output.
The attached dataset is a classical vaccine/placebo trial on 34 subjects. There are five visits (V1 >to V5) and I want to stratify readings of the marker measured in lab by site (A and C), and >bacteria (Positiv and Negative) at least for this example. I want to have my visit >readings(V2,V3,V4,V5) REFERENCED to the MEDIAN of the V1 readings within the stratified groups. So >the data if stratified should look like this: