我正在尝试将 df (xyz/latlonvalue) 中的点绘制为geom_sfshapefile 上的栅格。我尝试了另一篇文章中的答案,但没有一个有帮助。数据结构如下。
首先,我尝试raster::rasterFromXYZ(df)使用其他页面上的答案中的代码,但它不起作用。每次尝试都会收到相同的错误消息。
structure(list(x = c(-87.001233, -87.416633, -86.999683, -86.58395,
-86.998233, -86.998233, -86.998233, -86.998233, -87.416633, -87.416633,
-87.416633, -87.416633, -87.001233, -87.001233, -87.001233, -87.001233,
-87.001233, -87.001233, -87.001233, -87.001233, -87.001233, -87.001233,
-86.58395, -86.58395, -86.58395, -86.58395, -86.999683, -86.999683,
-86.999683, -86.999683, -86.916517, -86.965333, -87.233917, -86.721362,
-86.916517, -86.916517, -86.916517, -86.916517, -86.916517, -86.916517,
-86.916517, -86.916517, -86.916517, -86.916517, -86.766867, -86.766867,
-86.766867, -86.766867, -87.233917, -87.233917, -87.233917, -87.233917,
-86.965333, -86.965333, -86.965333, -86.965333, -86.721362, -86.721362,
-86.721362, -86.721362, -86.721362, -86.721362, -86.721362, -86.721362,
-86.721362, -86.721362, -86.721362, -86.37455, …Run Code Online (Sandbox Code Playgroud) 我正在尝试合并两个数据框(主数据框和子数据框)。我希望根据距离或更好的方式将“子”中的“变量”数据合并到“主”,无论哪个“子”行/站点最接近“主”行/站点。
library(sf)
a <- structure(list(`Site#` = c("Site1", "Site2", "Site3", "Site4", "Site5", "Site6"), Longitude = c(-94.609, -98.1391, -99.033, -98.49, -96.4309, -95.99), `Latitude` = c(38.922, 37.486111, 37.811, 38.364, 39.4402, 39.901)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
main <- st_as_sf(a, coords = c("Longitude", "Latitude"), crs = 4326)
b <- structure(list(Longitude = c(-98.49567, -96.22451, -98.49567, -98.941391, -95.91411, -99.031113), `Latitude` = c(38.31264,39.97692, 38.31264, 37.486111, 39.92143, 37.814171), Variable = c(400, 50, 100, 201, 99, 700)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", …Run Code Online (Sandbox Code Playgroud) 有没有办法对log(x+1)R 中的值向量的均值进行反向变换?我尝试使用包expm1()中的函数base,但数字肯定不正确。
df <- c(11, 24, 21, 63, 44, 95, 12, 43, 0, 5, 26, 22, 25, 48, 86, 2)
mean(df)
Run Code Online (Sandbox Code Playgroud)
这给了我们 32.9375
现在,如果我们这样做...
df.log1p <- log1p(df)
mean(df.log1p)
Run Code Online (Sandbox Code Playgroud)
这给了我们 3.0382116
现在,我可以对单个平均值进行反向转换以获得非log1p平均值 32.9375 吗?我曾经expm1(3.0382116)尝试过,但得到的是 19.86789。
这有可能吗?
问题:无法在R ...下面的代码中安装dplyr。有人提供解决方案吗?我正在使用Mac OS X Sierra和R版本1.0.136
> install.packages("dplyr")
There is a binary version available but the source version
is later:
binary source needs_compilation
dplyr 0.5.0 0.7.0 TRUE
Do you want to install from sources the package which needs compilation?
y/n:
y
installing the source package ‘dplyr’
trying URL 'https://cran.rstudio.com/src/contrib/dplyr_0.7.0.tar.gz'
Content type 'application/x-gzip' length 690938 bytes (674 KB)
==================================================
downloaded 674 KB
* installing *source* package ‘dplyr’ ...
** package ‘dplyr’ successfully unpacked and MD5 sums checked
** libs
xcrun: error: invalid …Run Code Online (Sandbox Code Playgroud) 有没有办法从这些字符串中获取日期?我只想隔离年份(例如,2019、2020、2021)
例如:USP_0318 2019 _H13
一个 tidyr 友好的答案将是理想的。
date <- c("USP_03182019_H13","DED_03212019_H1","EL_03202019_H8","EL_10082020_H6","DSP_05122021_H5")
# date
#1 USP_03182019_H13
#2 DED_03212019_H1
#3 EL_03202019_H8
#4 EL_10082020_H6
#5 DSP_05122021_H5
Run Code Online (Sandbox Code Playgroud) 我想知道为什么文本在图中的趋势更高......它不会与 facet_wrap 或 facet_grid 保持一致。在更复杂的数据集图中,由于重叠,文本难以辨认。
以下是重现情节和问题的数据和代码。将 geom="text" 添加到 stat_fit_glance,结果是Error: Discrete value supplied to continuous scale.
library(ggpmisc)
library(ggplot2)
DF <- data.frame(Site = rep(LETTERS[20:24], each = 4),
Region = rep(LETTERS[14:18], each = 4),
time = rep(LETTERS[1:10], each = 10),
group = rep(LETTERS[1:4], each = 10),
value1 = runif(n = 1000, min = 10, max = 15),
value2 = runif(n = 1000, min = 100, max = 150))
DF$time <- as.numeric(DF$time)
formula1 <- y~x
plot1 <- ggplot(data=DF,
aes(x=time, y= value2,group=Site)) + …Run Code Online (Sandbox Code Playgroud)