我有以下代码:
df=data.frame(time=as.factor(rep(0.5:9.5,each=10)),
roi=rep(1:10,10),
area=runif(100, 5.0, 7.5))
df$time=factor(df$time, levels=rev(levels(df$time)))
ggplot(data=df, aes(x=factor(roi), y=time, fill = area)) +
theme_minimal() +coord_fixed(ratio=1) +
geom_tile(colour = NA, width = 1.5, height = 1)+
scale_fill_gradient(low="black",high="white") +
scale_y_discrete(name="Time (min)",
expand =c(0,0),breaks=c(0.5,2.5,5.5,7.5,9.5),
labels=c(0,15,30,45,60))
如何让y标签靠近绘图区域。
非常感谢任何回复!
答案 0 :(得分:4)
在axis.ticks.length
中将theme
设置为零以删除此空格
ggplot(data=df, aes(x=factor(roi), y=time, fill = area)) +
theme_minimal() +
coord_fixed(ratio=1) +
geom_tile(colour = NA, width = 1.5, height = 1)+
scale_fill_gradient(low="black",high="white") +
scale_y_discrete(name="Time (min)",
expand =c(0,0),breaks=c(0.5,2.5,5.5,7.5,9.5),
labels=c(0,15,30,45,60)) +
theme(axis.ticks.length = unit(0, "lines"))