0

尝试使用 ggplot2 绘制光栅文件,但 x 轴值消失了。我很感激任何帮助

conne <- file("C:complete.bin","rb")
sd <- readBin(conne, numeric(), size=4,  n=1440*720, signed=TRUE)
y <-t(matrix((data=sd), ncol=1440, nrow=720))
f <- hist(y, breaks=30,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("Bi")+ 
    ylab("Frequency")+
    scale_fill_gradientn(colours = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)[1:12]))+
    ggtitle("2010")+
    theme(axis.title.x = element_text(size = 20))+
    theme(axis.title.y =  element_text(size = 20))+
    theme(plot.title = element_text(size = rel(2.5)))+
    scale_x_continuous(breaks = seq(seq(-0.5,0.5,0.1)),labels = seq(seq(-0.5,0.5,0.1)))

在此处输入图像描述

4

1 回答 1

3

正如@joran 暗示的那样,将最后一行更改为

scale_x_continuous(breaks = seq(-0.5,0.5,0.1),labels = seq(-0.5,0.5,0.1))

(我认为labels在这种情况下,这个论点可能是多余的。)当你运行时seq(seq(...)),你得到的是在seq向量上运行的结果,即从 1 到向量长度 (11) 的索引向量。该向量根本不与数据的 x 范围重叠,因此中断消失了...

于 2013-02-05T18:17:14.543 回答