如何将y轴强制为R中的最小和最大范围?

Bar*_*rry 19 r histogram ggplot2

如果你看一下下面的图(Y轴),你会发现,比例尺为00.20.我有其他的直方图,其中范围是从00.4.我想让所有这些从一致01并显示y01.

conne <- file("C:Aisdefined.bin","rb")
sd    <- readBin(conne, numeric(), size=4,  n=1440*720, signed=TRUE)
y     <- t(matrix((data=sd), ncol=1440, nrow=720))
r     <- raster(y)
f     <- hist(y, breaks=10,main="sm")

f$counts <- f$counts/sum(f$counts)
dat <- data.frame(counts= f$counts,breaks = f$mids)
ggplot(dat, aes(x = breaks, y = counts, fill =counts)) + 
   geom_bar(stat = "identity",alpha = 0.8) +
   xlab("Pearson correlation")+ ylab("Frequency") + 
   scale_x_continuous(breaks = seq(-1,1,0.250), labels = seq(-1,1,0.250)) +
   ggtitle("2011") + theme(axis.title.x = element_text(size = 20)) + 
   theme(axis.title.y = element_text(size = 20)) + 
   theme(text = element_text(size=20), 
   axis.text.x = element_text(angle = 90, vjust=1,colour="black"), 
   axis.text.y = element_text(colour="black")) + 
   theme(plot.title = element_text(size = rel(2.5))) + 
   scale_fill_gradientn(colours = "black")
Run Code Online (Sandbox Code Playgroud)

Jam*_*mes 28

只需添加:

+ coord_cartesian(ylim=c(0,1))
Run Code Online (Sandbox Code Playgroud)


Sim*_*lon 13

试试这个:

scale_y_continuous( limits = c(0,1), expand = c(0,0) )
Run Code Online (Sandbox Code Playgroud)

  • 注意:在比例上设置限制可能会排除数据. (2认同)