我在这个链接中有一个数据框 ,我有以下代码:
load("Fish11a.rda")
df=Fish11a
df=data.frame(Time=as.factor(df[,6]),RoiID=df[,3],Diameter=df[,8])
df$Time.hours=rep(1:10,each=104*max(df$RoiID),len=nrow(df))
df$Time <- factor(df$Time, levels=rev(levels(df$Time)))
df1=split(df,df$Time.hours)
br=lapply(split(df,df$Time.hours), function(x) {
br=data.frame(x[c(1,round(nrow(x)*(1:4)/4)),])
br$Min=c(0,15,30,45,60)
return(br)
})
hle1=function(dfr,br,tenplot) {
require(ggplot2)
require(gtable)
library(grid)
#start plot
g=ggplot(data=dfr, aes(x=factor(RoiID), y=Time, fill = Diameter)) +
theme_minimal() + coord_fixed(ratio=1) +
geom_tile(colour = NA, width = 1.5, height = 1)+
scale_fill_gradient(low="black",high="white")+
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(name="Time (min)",
expand = c(0,0),
breaks=br$Time,labels=br$Min)+
theme(axis.ticks.length = unit(0, "lines"))+
ggtitle(tenplot)+
theme(plot.title = element_text(size = 10, face = "bold"))
# calculate segment coordinates
segs <- c(.39, …Run Code Online (Sandbox Code Playgroud)