使用ggplot包在R中命名bin

时间:2017-04-11 10:06:17

标签: r graph histogram

我很难用ggplot包命名R中的箱子;我尝试使用names.args选项,但它没有用。

1 个答案:

答案 0 :(得分:0)

使用ggplot标签创建数据框,然后在ggplot中创建条形图:

# my example uses some raster data
require(ggplot2)
require(raster)
r <- raster("myraster.tif")
f <- hist(r, breaks=10)
dat <- data.frame(counts= f$counts,breaks = f$mids)

ggplot(dat, aes(x = breaks, y = counts, fill =counts)) + 
  geom_bar(stat = "identity")+
  scale_x_continuous(breaks = f$mids,labels = c("0 to 0.1","0.1 to 0.2","0.2 to 0.3","0.3 to 0.4","etc","etc","etc","etc","etc","etc"))