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
Run Code Online (Sandbox Code Playgroud)
这是人们在StackOverflow问题中注意到的一个问题:
和GitHub问题:
然而,本月早些时候(2015-07-09)关闭了GitHub问题,这让我对ggsubplot与R 3.2.1+合作表示乐观.
CRAN托管ggsubplot的0.3.2版本(2013-12-14发布)所以我使用package devtools
从GitHub安装ggsubplot.
我试图运行阿富汗伤亡示例代码,但我现在得到一个不同的错误:
Error in get(x, envir = this, inherits = inh)(this, ...) :
could not find function "aesply"
Run Code Online (Sandbox Code Playgroud)
我能做些什么来使这项工作?
另外,我如何确认我正在使用哪个版本的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")
Run Code Online (Sandbox Code Playgroud)
似乎ggsubplot
不再维护该包。
\n\n软件包 \xe2\x80\x98ggsubplot\xe2\x80\x99 已从 CRAN 存储库中删除。
\n以前可用的版本可以从存档中获取。
\n应维护者 garrett@rstudio.com 的要求,存档于 2016-01-11。
\n
在 GitHub ( https://github.com/garrettgman/ggsubplot ) 上,最后一次提交可以追溯到 2015 年 7 月 9 日。
\n在 R 3.3.2 下从 GitHub 安装devtools::install_github(\'garrettgman/ggsubplot\')
失败,并显示一条错误消息,抱怨缺少功能eval
。