已经搜索了所有相关的线程,但无法找到解决方案.
这是我的代码和附图结果:
g <-ggplot(NDVI2, aes(LAI2, NDVI, colour = Legend)) +
theme_bw (base_family = "Times") +
scale_colour_manual (values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black")) +
geom_point (size = 3) +
geom_smooth (aes(group = 1, colour = "Trendline"), method = "loess", size = 1, linetype = 5, se = FALSE) +
geom_smooth (aes(group = 1, colour = "Regression (log)"),linetype = 1, size=1.2,method = "lm", formula = y~ log(x), se = FALSE) +
labs (title = "Correlation of LAI and …
Run Code Online (Sandbox Code Playgroud) 以前我正在使用raster::crop
和raster::mask
使用Spatial*类的shapefile,读入使用rgal::readOGR
.
我只是"升级"我的脚本sf
用于阅读和操作多边形.
raster::crop
期望'范围'对象作为第二个参数.到目前为止,这是从Spatial*对象中自动提取的.所以我可以做到raster::crop(raster, polygon)
.
为了使用一个sf
对象,我可以称之为raster::crop(raster, as.vector(st_bbox(polygon)))
一个丑陋的解决方法.
由于raster::mask
显然期望Raster* object or a Spatial* object
唯一的解决方案是使用将sf
对象强制回空间*对象as("Spatial")
.
我假设这个问题推广到所有raster
函数?我是否忽略了某些东西,或者只是raster
包裹没有(还)与sf
对象一起工作?
我使用构建我的R包,--no-build-vignettes
因为晕影需要很长时间才能运行.因此,我还想避免"R CMD Check"检查晕影重建.
我试着用--no-check-vignettes
.然而,这会被忽略(不确定它是否存在).
忽略我的小插图的另一个原因是我在Travis CI上遇到麻烦,因为这一步超过10分钟(导致构建中止).
有没有办法避免建立和检查R包的晕影?(除了设置所有的小插图块eval = FALSE
)
我正在使用.packages = (.packages())
. 但是,我找不到如何抑制包启动消息。由于它们是为每个分配的核心加载的,因此该列表会变得很长。我已经尝试suppressMessages()
在函数调用和.packages
参数周围包装标准调用等,但没有成功。
foreach(i = x, .packages = (.packages()))
Run Code Online (Sandbox Code Playgroud)
我在通用函数中使用 foreach 调用,因此它需要适应用户先验加载的任何包。我可以在 foreach 调用中使用 apply 调用,并在全局环境中加载所有包,但我认为foreach
需要在其.packages
参数中加载它?
如果有更好的方法来做到这一点,请告诉我。
require(ggplot2)
require(cowplot)
d = iris
ggplot2::ggplot(d, aes(factor(0), Sepal.Length)) +
geom_violin(fill="black", alpha=0.2, draw_quantiles = c(0.25, 0.5, 0.75)
, colour = "red", size = 1.5) +
stat_boxplot(geom ='errorbar', width = 0.1)+
geom_boxplot(width = 0.2)+
facet_grid(. ~ Species, scales = "free_x") +
xlab("") +
ylab (expression(paste("Value"))) +
coord_cartesian(ylim = c(3.5,9.5)) +
scale_y_continuous(breaks = seq(4, 9, 1)) +
theme(axis.text.x=element_blank(),
axis.text.y = element_text(size = rel(1.5)),
axis.ticks.x = element_blank(),
strip.background=element_rect(fill="black"),
strip.text=element_text(color="white", face="bold"),
legend.position = "none") +
background_grid(major = "xy", minor = "none")
Run Code Online (Sandbox Code Playgroud)
据我所知,箱形图中的方框末端分别代表25%和75%的分位数,中位数= 50%.因此,他们应等于其通过绘制的0.25/0.5/0.75分位数geom_violin
的 …
根据这个答案,应该可以使用以下语法
[link](url){:target="_blank"}
Run Code Online (Sandbox Code Playgroud)
使用时在新标签页中打开链接pandoc
.
但是,似乎不支持此选项,因为转换为html时无法识别该选项.
我正在使用rmarkdown
它依赖于pandoc
后台.
是否可以使用pandoc
,如果是,如何使用?
以下与scale_x_continuous
结合使用geom_sf
将完全删除 x 轴标签。我假设指定的中断在 ggplot 对象中并不真正存在,随后根本没有显示。
这是由从 EPSG 32717 到 EPSG 4326 的自动转换引起的coord_sf()
吗?
data(ecuador, package = "sperrorest")
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2
library(ggplot2)
data = st_as_sf(ecuador, coords = c("x", "y"), crs = 32717)
ggplot(data) +
geom_sf()
Run Code Online (Sandbox Code Playgroud)
ggplot(data) +
geom_sf() +
scale_x_continuous(breaks = c(79.085, 79.055))
Run Code Online (Sandbox Code Playgroud)
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.3 (2017-11-30)
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate …
Run Code Online (Sandbox Code Playgroud) 我有以下数据:
dput(dat)
structure(list(Band = c(1930, 1930, 1930, 1930, 1930, 1930, 1930,
1930, 1930, 1930, 1930, 1930, 1930, 1930, 1930, 1930, 1930, 1930
), Reflectance = c(25.296494, 21.954657, 18.981184, 15.984661,
14.381341, 12.485372, 10.592539, 8.51772, 7.601568, 7.075429,
6.205453, 5.36646, 4.853167, 4.21576, 3.979639, 3.504217, 3.313851,
2.288752), Number.of.Sprays = c(0, 1, 2, 3, 5, 6, 7, 9, 10, 11,
14, 17, 19, 21, 27, 30, 36, 49), Legend = structure(c(4L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, …
Run Code Online (Sandbox Code Playgroud) 在 RStudio 中编写 .rmd 或 .Rnw 报告时,大纲视图会显示代码块和常规部分。虽然代码块显示为斜体,但常规部分不是。然而,编写具有许多相似命名块的大型报告将导致具有许多相似标签的非常庞大的大纲视图。
目前有没有办法关闭其中一个?常规部分或代码块。
我想使用 mlr 对 R 中的右删失生存数据运行 xgboost。xgboost 代码列出了一个目标函数survival:cox,其中表示:
生存:cox:右删失生存时间数据的 Cox 回归(负值被视为右删失)。
我正在使用的 Mlr 2 仅支持回归和分类学习器的 xgboost。如果我尝试使用 xgboost 的内置回归学习器,它会使用 mse 作为评估指标。所以我尝试将指标更改为 cindex 并收到错误
措施:cindex cindex
FUN(X[[i]], ...) 中的错误:措施 cindex 不支持任务类型 regr!
所以然后我尝试为 xgboost 编写一个新的生存学习器,它只是回归学习器的副本,但将“Regr”更改为“Surv”,但当然它期望目标有 2 列 - 时间和状态 - 并且不接受负时间,而 xgboost 只期望一列 - 时间 - 并假设任何具有负时间值的行都会被审查。
以下是我尝试过的。有什么办法可以在 mlr2 或 mlr3 中实现这一点吗?
data(veteran)
veteran_xgb <- veteran
veteran_xgb <- veteran_xgb[c("trt", "karno", "diagtime", "age", "prior", "time")]
veteran_xgb$time <- ifelse(veteran$status==1, veteran$time, -veteran$time)
xgb.task <- makeRegrTask(id="XGBOOST_VET", data = veteran_xgb, target="time")
xgb_learner <- makeLearner(id="xgboost",
cl="regr.xgboost", …
Run Code Online (Sandbox Code Playgroud) 我处理一些形状文件和栅格。
当我逐行(或部分)执行我的脚本时,一切都按预期运行。但是,如果我将它作为一个整体执行(源代码或 STRG+A 然后 STRG+ENTER),它会在以下部分引发错误:
# ... some code
list = list()
list = foreach(i = seq(from = 9, to = 80, by = 5)) %dopar% {
df[which(df@data$column.name > i), ]
}
# ... some code
Run Code Online (Sandbox Code Playgroud)
错误信息: Error in { : task 2 failed - "Object of type 'S4' is not subsettable"
fishnet
SpatialPolygonsDataFrame在哪里。代码子集我的 SpPolDaFr 所以我在列表中写了 15 个子集 SpPolDaFr。
我在想也许是foreach
原因。但是,我有其他foreach
先验调用,它们运行良好。我进行doParallel
循环是因为我的 SpPolDaFr 大小为 11 GB 以加快速度。
我正在尝试使用 R 中的包“iml”从 H2O 中创建的 GBM 模型创建 SHAP 值图。
当我尝试使用该函数创建 R6 Predictor 对象时,Predictor.new()
我收到一条错误,指出Error : all(feature.class %in% names(feature.types)) is not TRUE
。
由此,我猜测其中一个要素类存在某些不正确的内容,但这只是基于错误消息字面意思的有根据的猜测。
这是匿名数据的示例(我无法共享真实数据,因为它是机密的):
structure(list(dlr_id_cur = c(1, 2), date_eff = structure(c(16014,
15416), class = "Date"), new_vec_ind = structure(c(1L, 1L), .Label = c("NNA",
"UNA"), class = "factor"), cntrct_term = c(9587879614862828,
19), amt_financed = c(9455359, 65561175), reg_payment = c(885288,
389371), acct_stat_cd = structure(c(3L, 3L), .Label = c("11",
"22", "33"), class = "factor"), base_rental = c(1, 626266), down_pymt = c(2,
6654661), …
Run Code Online (Sandbox Code Playgroud) 给定foo
和mock
,有没有一种方法可以代替foo
类?matrix
array
调用as.matrix()
放入foo
错误的结构。我希望foo
成为一个matrix
,而不是两行。
foo = structure(c(0.729504668890744, 0.190464932275543, 0.0800303988337127),
.Dim = c(1L, 3L, 1L),
.Dimnames = list(NULL, c("A", "B",
"C"), "NA"))
class(foo[, , 1L])
#> [1] "numeric"
print(foo[, , 1L])
#> A B C
#> 0.7295047 0.1904649 0.0800304
mock = structure(c(0.550876469322338, 0.729504668890744, 0.342833178276825,
0.190464932275543, 0.106290352400837, 0.0800303988337127),
.Dim = c(2L,
3L, 1L),
.Dimnames = list(NULL, c("A", "B", "C"),
"NA"))
class(mock[, , 1L])
#> [1] "matrix"
print(mock[, , …
Run Code Online (Sandbox Code Playgroud)