我的问题是关于如何保存ggplot2纵横比的图表。如果我制作一个简单的图形并使用 设置绘图的尺寸ggsave(),则绘图将占据已保存文件的整个区域。
library(ggplot2)
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.2, PROJ 5.2.0
#> WARNING: different compile-time and runtime versions for GEOS found:
#> Linked against: 3.7.1-CAPI-1.11.1 27a5e771 compiled against: 3.7.0-CAPI-1.11.0
#> It is probably a good idea to reinstall sf, and maybe rgeos and rgdal too
df <- data.frame(
longitude = -47,
latitude = 45
)
p <- ggplot(df, aes(x = longitude, y = latitude)) +
geom_point() +
theme(
plot.background = element_rect(fill = "black")
) …Run Code Online (Sandbox Code Playgroud) 我在我的R包中使用rogyxen2模板.按照建议,我将模板R文件添加到包目录中名为"man-roxygen"的文件夹中.
但是,当IR CMD检查时,我得到以下注释:
在顶层找到的非标准文件/目录:'man-roxygen'
有任何解决这个问题的方法吗?
干杯,菲利普
我有以下数据
library(tidyr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(data.table)
#>
#> Attaching package: 'data.table'
#> The following objects are masked from 'package:dplyr':
#>
#> between, first, last
df <- structure(list(filename = c("PS92_019-6_rovT_irrad.tab", "PS92_019-6_rovT_irrad.tab",
"PS92_019-6_rovT_irrad.tab", "PS92_019-6_rovT_irrad.tab"), depth = c(5,
10, 20, 75), ps = c(3.26223404971255, 3.38947945477306, 3.97380593851983,
0.428074807655144)), row.names = c(NA, -4L), class = c("tbl_df", …Run Code Online (Sandbox Code Playgroud) 我正在使用lme4R 包来创建使用该lmer()函数的线性混合模型。在这个模型中,我有四个随机效应和一个固定效应(拦截)。我的问题是关于随机效应的估计方差。是否有可能以类似的方式指定的协方差参数的初始值,因为它可以在完成SAS与PARMS争论。
在以下示例中,估计方差为:
c(0.00000, 0.03716, 0.00000, 0.02306)
Run Code Online (Sandbox Code Playgroud)
我想将这些修复为(例如)
c(0.09902947, 0.02460464, 0.05848691, 0.06093686)
Run Code Online (Sandbox Code Playgroud)
所以估计没有。
> summary(mod1)
Linear mixed model fit by maximum likelihood ['lmerMod']
Formula: log_cumcover_mod ~ (1 | kildestationsnavn) + (1 | year) + (1 |
kildestationsnavn:year) + (1 | proevetager)
Data: res
AIC BIC logLik deviance df.resid
109.9 122.9 -48.9 97.9 59
Scaled residuals:
Min 1Q Median 3Q Max
-2.1056 -0.6831 0.2094 0.8204 1.7574
Random effects:
Groups Name Variance …Run Code Online (Sandbox Code Playgroud) 我有这个数据:
\nlibrary(data.table)\n\nbioargo <- data.table(\n grp = c("a", "a", "b", "b"),\n val = 1:4,\n x = c(2.1, 2.2, 1.9, 3)\n)\n\nhplc <- data.table(\n x = c(2, 2.3),\n z = c("foo", "bar")\n)\nRun Code Online (Sandbox Code Playgroud)\n我想将两个data.tables 合并到最接近的x值上,但通过grp,因此输出如下(即 \xc2\xa0 对于 中的每一行hplc,获取最接近x的每grp行bioargo):
data.table(\n x = c(2, 2.3),\n z = c("foo", "bar"),\n val = c(1, 3, 2, 2)\n)\n#> x z val\n#> 1: 2.0 foo 1\n#> 2: 2.3 bar 3\n#> 3: 2.0 foo …Run Code Online (Sandbox Code Playgroud) library(tidyverse)\nlibrary(sf)\n#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1\nRun Code Online (Sandbox Code Playgroud)\n我有一些数据,我想计算沿定义路径的每个点(站)之间的距离。
\ndat <-\n structure(\n list(\n name = c(\n "Untitled Path",\n "St34B",\n "St35N",\n "St36F",\n "St37N",\n "St38B",\n "Untitled Path",\n "St39N"\n ),\n description = c(\n NA_character_,\n NA_character_,\n NA_character_,\n NA_character_,\n NA_character_,\n NA_character_,\n NA_character_,\n NA_character_\n ),\n timestamp = structure(\n c(\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_\n ),\n class = c("POSIXct", "POSIXt"),\n tzone = ""\n ),\n begin = structure(\n c(\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_,\n NA_real_\n ),\n class = c("POSIXct", "POSIXt"),\n …Run Code Online (Sandbox Code Playgroud) 我有以下多边形。
\nlibrary(ggplot2)\nlibrary(sf)\n#> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE\n\npoly <- st_polygon(list(rbind(\n c(-90, 70),\n c(-40, 70),\n c(-40, 74),\n c(-90, 74),\n c(-90, 70)\n))) |>\n st_sfc() |>\n st_segmentize(5) |>\n st_set_crs(4326) |>\n st_as_sf() |>\n st_transform(3413) |>\n st_cast("POLYGON")\n\nggplot() +\n geom_sf(data = poly) +\n theme(\n panel.background = element_blank()\n )\nRun Code Online (Sandbox Code Playgroud)\n
是否可以按照多边形(而不是绘图区域)的 \xe2\x80\x9cshape\xe2\x80\x9d 的方式放置坐标标签?
\n创建于 2023-01-11,使用reprex v2.0.2
\n如何为我的S3类实现通用函数名称,以便我可以"设置"我的对象的名称.
要检索名称,我只需将其实现为:
names.myobject <- function(x, ...){
x$y
}
Run Code Online (Sandbox Code Playgroud)
然后我可以这样做:
names(myobject)
Run Code Online (Sandbox Code Playgroud)
但我不能用它来设置以下形式的名称:
names(myobject) <- "a"
Run Code Online (Sandbox Code Playgroud)
我想的是:
names.myobject <- function(x, newname){
x$y <- newnames
}
Run Code Online (Sandbox Code Playgroud)
如何实现"设置"形式的名称?
我试图生成类似于此的立体图:
我想要做的是添加:
这可以在基础R或ggplot2中.任何帮助表示赞赏.
到目前为止我的尝试
library(rgdal)
library(raster)
proj <- "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"
data("wrld_simpl", package = "maptools")
wm <- crop(wrld_simpl, extent(-180, 180, 45, 90))
plot(wm)
Run Code Online (Sandbox Code Playgroud)
wm <- spTransform(wm, CRSobj = CRS(proj))
plot(wm)
Run Code Online (Sandbox Code Playgroud)
我想使用该magick包创建一个 3 x 3 的高分辨率 \xe2\x80\x9cmontage\xe2\x80\x9d 。
library(magick)\n#> Linking to ImageMagick 6.9.7.4\n#> Enabled features: fontconfig, freetype, fftw, lcms, pango, x11\n#> Disabled features: cairo, ghostscript, rsvg, webp\n\n# Read the image and resize it\nfrink <- image_read("https://jeroen.github.io/images/frink.png")\nfrink <- image_resize(frink, "100x")\n\n# Create 1 column with 3 rows\ncol <- image_append(rep(frink, 3), stack = TRUE)\n\n# "Combine" 3 columns\ni <- image_append(c(col, col, col))\n\ni\nRun Code Online (Sandbox Code Playgroud)\n\n
所以我的问题是如何将其保存为高分辨率 png(例如 300 DPI)?我正在考虑使用image_write(),但显然我无法在那里设置我想要的分辨率。
# This is not working\n# image_write(i, tempfile(), res = 300)\nRun Code Online (Sandbox Code Playgroud)\n\n谢谢你,\n菲尔 …
有没有办法用 ggplot2 更改图例中键的宽度和高度?在下面的示例中,我想用可以调整宽度和高度的矩形替换图例中的点。我尝试使用keywidth没有成功。
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
theme(
legend.position = "top",
legend.title = element_blank()
) +
guides(
color = guide_legend(
label.position = "top",
override.aes = list(shape = 15, size = 5),
keywidth = unit(2, "cm") # This is not giving me what I was expecting.
)
)
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020-07-23 创建
我有以下向量:
v <- c(2L, 2L, NA, NA, NA, NA, 8L, NA)
Run Code Online (Sandbox Code Playgroud)
如何使用前一个系列的值+ 1替换缺失值,使其变为:
c(2L, 2L, 3L, 3L, 3L, 3L, 8L, 9L)
Run Code Online (Sandbox Code Playgroud) r ×12
ggplot2 ×3
data.table ×2
gis ×2
r-sf ×2
cartography ×1
cran ×1
imagemagick ×1
legend ×1
lme4 ×1
maps ×1
roxygen2 ×1