r - ggsubplot 是否适用于 R 3.2.1+?

标签 r ggplot2

CRAN 提供的 ggsubplot 版本与 R 的最新版本(例如 3.1.1)不兼容,并且运行 ggsubplot 示例会返回关于

Error in layout_base(data, vars, drop = drop) : 
  At least one layer must contain all variables used for facetting

这是人们在 StackOverflow 问题中注意到的一个问题:
  • Cannot run any ggsubplot examples
    Plotting bar chart on map using ggplot2

  • 和 GitHub 问题:
  • https://github.com/garrettgman/ggsubplot/issues/14
    https://github.com/garrettgman/ggsubplot/issues/10

  • 然而,GitHub 问题在本月早些时候(2015-07-09)被关闭,这让我对 ggsubplot 将与 R 3.2.1+ 一起工作感到乐观

    CRAN hosts version 0.3.2 of ggsubplot (released 2013-12-14)所以我使用了包 devtools从 GitHub 安装 ggsubplot。

    我尝试运行阿富汗伤亡示例代码,但现在出现不同的错误:
    Error in get(x, envir = this, inherits = inh)(this, ...) : 
      could not find function "aesply"
    

    有什么我可以做的事情吗?

    另外,我如何确认我使用的是哪个版本的 ggsubplot?

    我试过的代码如下:
    ## install.packages("devtools")
    
    library(devtools)
    
    dev_mode(on=T)
    
    install_github("garrettgman/ggsubplot")
    
    library(ggplot2)
    ## library(ggsubplot) - I just loaded this, right?
    library(maps)
    library(plyr)
    
    # getbox by Heike Hoffman, 
    # https://github.com/ggobi/paper-climate/blob/master/code/maps.r
    getbox <- function (map, xlim, ylim) {
      # identify all regions involved
      small <- subset(map, (long > xlim[1]) & (long < xlim[2]) & (lat > ylim[1]) & (lat < ylim[2]))
      regions <- unique(small$region)
      small <- subset(map, region %in% regions)  
    
      # now shrink all nodes back to the bounding box
      small$long <- pmax(small$long, xlim[1])
      small$long <- pmin(small$long, xlim[2])
      small$lat <- pmax(small$lat, ylim[1])
      small$lat <- pmin(small$lat, ylim[2])
    
      # Remove slivvers
      small <- ddply(small, "group", function(df) {
        if (diff(range(df$long)) < 1e-6) return(NULL)
        if (diff(range(df$lat)) < 1e-6) return(NULL)
        df
      })
    
      small
    }
    
    
    ## map layer
    ## adapted from map_nasa:
    # https://github.com/ggobi/paper-climate/blob/master/code/maps.r
    
    # assembling data
    world <- map_data("world")
    
    # building afghanistan layer
    afghanistan <- getbox(world, c(60,75), c(28, 39))
    map_afghanistan <- list(
      geom_polygon(aes(long, lat, group = group), data = afghanistan, 
                   fill = "white", colour = "black", inherit.aes = FALSE, 
                   show_guide = FALSE),
      scale_x_continuous("", breaks = NULL, expand = c(0.02, 0)),
      scale_y_continuous("", breaks = NULL, expand = c(0.02, 0)))
    
    
    ## 2d bin with bar chart subplots displaying data in each region
    ggplot(casualties) +
      map_afghanistan +
      geom_subplot2d(aes(lon, lat,
                         subplot = geom_bar(aes(victim, ..count.., fill = victim))),
                     bins = c(15,12), ref = NULL, width = rel(0.8)) +
      coord_map()+
      theme(legend.position = "right")
    

    最佳答案

    好像是包裹ggsubplot不再维护。
    Message on CRAN (as of 2016-12-23) :

    Package ‘ggsubplot’ was removed from the CRAN repository.

    Formerly available versions can be obtained from the archive.

    Archived on 2016-01-11 as requested by the maintainer garrett@rstudio.com.


    在 GitHub ( https://github.com/garrettgman/ggsubplot ) 上,最后一次提交可以追溯到 2015-07-09。
    在 R 3.3.2 下从 GitHub 安装 devtools::install_github('garrettgman/ggsubplot')失败,错误消息提示缺少函数 eval .

    关于r - ggsubplot 是否适用于 R 3.2.1+?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31493592/

    相关文章:

    r - RStudio 中下载文件失败

    r - ggplot2 中的 qqline 与 facets

    R如何将文本相对于 Axis 放置在ggplot上

    r - 解释 ANOVA 表的 R 重要性代码?

    javascript - 使用 uiOutput 用 Shiny 的键盘触发 actionButton

    regex - 在最后一次出现数字时拆分,取第二部分

    r - 如何使用 ggplot2 为曲线下的区域着色

    r - 重叠具有不同变量的ggplot2直方图

    r - 在 r 中按年份分面月度数据 - 没有数据出现的月份

    javascript - 如何使用 Shiny 的javascript函数?