timegraph <- function(time,scores,x,y,unit.of.time){
#color
transparency=.5
green1=rgb(45,201,55,transparency*255,maxColorValue = 255)
green2=rgb(153,193,64,transparency*255,maxColorValue = 255)
yellow1=rgb(231,180,22,transparency*255,maxColorValue = 255)
orange1=rgb(219,123,43,transparency*255,maxColorValue = 255)
red1=rgb(204,50,50,transparency*255,maxColorValue = 255)
clear=rgb(0,0,0,transparency*255,maxColorValue = 255*4)
coords=data.frame(time,scores)
plot(-666, xlab=unit.of.time,
ylab="Attainment score (%)",
xaxs="i",yaxs="i",
xlim=c(time[1],time[length(time)]),
ylim=c(y[1],y[length(y)]),
par(las=1))
x=c(0,30,40,50,100)
y=c(0,25,50,75,100)
if(length(x)==4){
colorscale<-c(clear,red1,yellow1,green1)
}else{
if(length(x)==5){
colorscale<-c(clear,red1,orange1,yellow1,green1)
}else{
if(length(x)==6){
colorscale<-c(clear,red1,orange1,yellow1,green2,green1)
}else{
print("you have have to define your own color scale. For example, if you have 7 points, colorscale <-c(clear,red1,orange1,...) ")}
}}
{for(i in length(x):1){
colorpicker=colorscale[i]
rect(xleft = time[1],ytop = y[i],xright = time[length(time)],
ybottom = y[1], col="white",border = clear)
rect(xleft = time[1],ytop = y[i],xright = time[length(time)],
ybottom = y[1], col=colorpicker,border = colorpicker)}
}
par(new=TRUE)
plot(coords,xlab=unit.of.time,
ylab="",
xaxs="i",yaxs="i",
xlim=c(time[1],time[length(time)]),
ylim=c(y[1],y[length(y)]),
pch=20)
lines(coords)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.