Вот некоторый код, использующий удивительный пакет ggplot2 , который производит виды графиков, которые я хотел бы в этом случае.Проверьте документацию и веб-сайт Хэдли, чтобы настроить их.
#Assume ID, and Ward are factors, and WRES. shouldn't be
pkso$ID<-as.factor(pkso$ID)
pkso$WARD<-as.factor(pkso$WARD)
pkso$WRES<-as.numeric(pkso$WRES.)
#display clean data for SO fans
dput(pkso)
library(ggplot2)
#draw a graph TAD Vs IPRE,DV,PRED as a whole which i have no issues in producing them.
#first melt the data into a narrow format, then plot
pksomelt<-melt(pkso, id.vars=c("ID","TIME","TAD","AMT","BL","WARD"))
pksomelt$value<-as.numeric(pksomelt$value)
#now subset that data for what we want
pksomelt<-subset(pksomelt,variable %in% c("IPRE","DV","PRED"))
#now plot, using facet_wrap to seperate variables
pkplot1<-ggplot(pksomelt, aes(TAD, value)) +
geom_point() +
scale_shape(solid = FALSE) +
facet_wrap( ~ variable)
print(pkplot1)
#Second part is I am trying to produce an individual graph for ID (n=35) so 35 graph for (TAD Vs IPRE,DV,PRED)
#so, for an individual plot
pkplot2<-ggplot(subset(pksomelt, ID == "1"), aes(TAD, value)) +
geom_point() +
scale_shape(solid = FALSE) +
facet_wrap( ~ variable)
print(pkplot2)
# or, for presenting, you could do all 35 spread across 6 plots, but seperated, by using facet_grid
i<-ceiling(max(as.numeric(pksomelt$ID))/6) # Calculate number of ID's per plot
pkplot3<-ggplot(subset(pksomelt, as.numeric(pksomelt$ID) > (i*0) & as.numeric(pksomelt$ID) < (i*1)+1),
aes(TAD, value)) +
geom_point() +
scale_shape(solid = FALSE) +
facet_grid(ID ~ variable)
print(pkplot3)
pkplot4<-ggplot(subset(pksomelt, as.numeric(pksomelt$ID) > (i*1) & as.numeric(pksomelt$ID) < (i*2)+1),
aes(TAD, value)) +
geom_point() +
scale_shape(solid = FALSE) +
facet_grid(ID ~ variable)
print(pkplot4) # ect etc
#Third Part is to try and produce a graph based on Ward (TAD Vs IPRE,DV,PRED) which will have 5 graphs.
#Again, use Facet_grid to seperate different wards, let's also add lines to show it's possible
pkplot5<-ggplot(pksomelt, aes(TAD, value)) +
geom_point(aes(colour=ID)) + geom_line(aes(colour=ID)) +
scale_shape(solid = FALSE) +
facet_grid(WARD ~ variable, scales="free")
print(pkplot5)