在导入ggplot2的包中使用ggplotGrob函数时,找不到它
我有一个包裹在这里 它利用了ggplot2,所以我将它导入到我的名称空间文件和描述文件中 名称空间:在导入ggplot2的包中使用ggplotGrob函数时,找不到它,r,import,ggplot2,namespaces,dependencies,R,Import,Ggplot2,Namespaces,Dependencies,我有一个包裹在这里 它利用了ggplot2,所以我将它导入到我的名称空间文件和描述文件中 名称空间: # Generated by roxygen2 (4.1.0): do not edit by hand export(HybRIDS) exportClasses(HybRIDS) import(Biostrings) import(ape) import(ggplot2) import(grid) import(gridExtra) importFrom(png,readPNG) useD
# Generated by roxygen2 (4.1.0): do not edit by hand
export(HybRIDS)
exportClasses(HybRIDS)
import(Biostrings)
import(ape)
import(ggplot2)
import(grid)
import(gridExtra)
importFrom(png,readPNG)
useDynLib(HybRIDS)
说明:
Package: HybRIDS
Type: Package
Title: Detection and dating of Recombinant Regions in DNA sequence data.
Version: 1.0
Date: 2014-12-18
Author: Ben J. Ward
Maintainer: Ben J. Ward <b.ward@uea.ac.uk>
Description: An R package for the detection and dating of
Recombinant Regions in DNA sequence data.
License: GPL-2
Depends: methods
Imports:
Rcpp (>= 0.11.0),ggplot2,grid,gridExtra,png,ape,Biostrings
LinkingTo: Rcpp
Suggests: knitr,testthat
VignetteBuilder: knitr
我在RStudio中的追踪将我带到包中的以下几行:
arrangeGrob(bars, legendgrob, widths = c(1, 0.13), ncol = 2) at TripletReference.R#244
6 plotBars(plottingSettings) at TripletReference.R#157
5 x$plotTriplet(plotSettings) at TripletReference.R#361
4 FUN(X[[1L]], ...)
3 lapply(tripletsToPlot, function(x) x$plotTriplet(plotSettings)) at TripletReference.R#361
2 triplets$plotTriplets(Selections, plottingSettings) at HybRIDSObject.R#253
1 test$plotTriplets()
在三重引用.R#244处使用arrangeGrob的那一行非常简单。它有两个输入,一个是函数中较早时通过以下方式生成的ggplot对象:
bars <- ggplot(plottingFrame, aes(x = X, y = as.factor(Y))) +
geom_raster(aes(fill = colour)) + scale_fill_identity() +
xlab("Approximate Base Position") +
ylab("Sequence Name") +
scale_x_continuous(breaks = c(seq(from = 1, to = plottingSettings$MosaicScale, by = plottingSettings$MosaicScale / 10), plottingSettings$MosaicScale), labels = c(frame$bpX[seq(from = 1, to = plottingSettings$MosaicScale, by = plottingSettings$MosaicScale / 10)], max(frame$bpX))) +
scale_y_discrete(labels = c(ContigNames[3], ContigNames[2], ContigNames[1]))
所以我知道已经加载了ggplot2名称空间——我的问题是,为什么我的包会抛出这个错误,即使我已经导入了ggplot2?ggplot2现在唯一依赖的是统计数据和方法
谢谢,
Ben W.尝试在描述文件中的“依赖”而不是“导入”下添加
ggplot2
在使用grid.arrange
函数时,我遇到了类似的问题,这个解决方案对我很有效
我的,诚然是初步的,对这个问题的理解是,
gridExtra
在ggplot2
库尚未加载时调用了ggplotGrob
函数。我想我已经找到了答案-这是因为gridExtra没有导入ggplot2,所以gridExtra的arrangeGrob没有找到ggplot2的ggplotGrob吗?一个潜在的问题我看到的问题是gridExtra
依赖于grid
,所以当您导入gridExtra
时,它基于“grid
的功能将中断。你必须把gridExtra
放在dependens
中。这也是我推断出来的——或者至少是类似的,gridExtra使用了ggplot2中的东西,但ggplot2只是一个例子。因此,and搜索它试图通过搜索路径调用的ggplot2函数,即附加的包,而不是通过其导入。
bars <- ggplot(plottingFrame, aes(x = X, y = as.factor(Y))) +
geom_raster(aes(fill = colour)) + scale_fill_identity() +
xlab("Approximate Base Position") +
ylab("Sequence Name") +
scale_x_continuous(breaks = c(seq(from = 1, to = plottingSettings$MosaicScale, by = plottingSettings$MosaicScale / 10), plottingSettings$MosaicScale), labels = c(frame$bpX[seq(from = 1, to = plottingSettings$MosaicScale, by = plottingSettings$MosaicScale / 10)], max(frame$bpX))) +
scale_y_discrete(labels = c(ContigNames[3], ContigNames[2], ContigNames[1]))
legendgrob <- rasterGrob(image=legend)
function (x)
{
ggplot_gtable(ggplot_build(x))
}
<environment: namespace:ggplot2>