【问题标题】:Naming bins in R using the ggplot package使用 ggplot 包在 R 中命名 bin
【发布时间】:2017-04-11 10:06:17
【问题描述】:

我正在努力用 ggplot 包命名 R 中的垃圾箱;我尝试使用 names.args 选项,但没有成功。

【问题讨论】:

    标签: r graph histogram


    【解决方案1】:

    使用 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"))
    

    【讨论】:

    • 一定要使用光栅功能吗?
    • 我不太明白你为什么要创建“r”和“f”?该代码似乎对我不起作用。
    • @Bonsaibubble 你几乎没有什么工作要做:你有什么样的数据,你想用它做什么(我猜是做一个直方图),这些“名字”出现在哪里(x轴?)。我只是举了一个我想到的例子。不,此示例纯粹用于栅格。
    猜你喜欢
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 2021-03-05
    • 2015-05-25
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多