我怎样才能mutate_if()改变bto的值NA以防万一a > 25
我可以做到ifelse,但我觉得mutate_if是为这样的任务而创建的。
library(tidyverse)
tbl <- tibble(a = c(10, 20, 30, 40, 10, 60),
b = c(12, 23, 34, 45, 56, 67))
Run Code Online (Sandbox Code Playgroud) 下面是使用 R 中的包查找从“纽约世贸中心一号”到“纽约麦迪逊广场公园”的路线、旅行时间和旅行距离的示例osrm。(我是从R 中的 Road Routing中学到的 )。这里的行车时间是 10.37 分钟。
我想创建一个用于可视化的视频。
问:如何创建车辆(由标记表示)沿路线从“纽约世贸中心一号”移动到“纽约麦迪逊广场公园”的动画?
理想情况下,我们应该知道每个路段的速度。但是让我们假设车辆在两个位置之间以恒定速度(= 距离/时间)不停地移动。
我们也可以简单地使用tmap代替传单来创建动画。
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
# 1. One World Trade Center, NYC
# 2. Madison Square Park, NYC
adresses <- c("285 Fulton St, New York, NY 10007",
"11 Madison Ave, New York, NY 10010")
# geocode the two addresses & transform to {sf} data structure
data <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
osroute <- …Run Code Online (Sandbox Code Playgroud) 这是关于如何创建沿路线从 A 到 B 的车辆移动动画的后续问题?. 我可以学习如何为沿路线从 A 到 B 移动的车辆设置动画。谢谢您的帮助!
但是是否可以通过添加时间线(带有显示瞬时时间和相应事件的移动标记)来制作一个自我解释的视频(对于假设的客户)。 时间线示例
例如 - 这是一个示例事件序列 -
library(sf)
library(dplyr)
library(tidygeocoder)
library(osrm)
library(lubridate)
# adresses
adresses <- c("285 Fulton St, New York, NY 10007", # One World Trade Center
"11 Madison Ave, New York, NY 10010",
"Rockefeller Center, 45 Rockefeller Plaza, New York, NY 10111")
# geocoded addresses
geocoded_addresses <- tidygeocoder::geo(adresses, method = "osm") %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
# reference time
t <- as_datetime("2021-08-23 …Run Code Online (Sandbox Code Playgroud) 如何重新排列 tibble 中的行?
我希望重新排序行,以便: x = "c" 的行位于小标题的底部,其他所有内容保持不变。
library(dplyr)
tbl <- tibble(x = c("a", "b", "c", "d", "e", "f", "g", "h"),
y = 1:8)
Run Code Online (Sandbox Code Playgroud) 我生成mylist的包含三个小标题。
创建 mylist 后,如何创建三个 tibbles A_complete,B_complete并C_complete通过分别绑定 mylist 的所有 As、Bs、C 行。
mylist <- list()
for (iter in 1:10)
{
mylist[[iter]] <- list(A = tibble(x = runif(5)),
B = tibble(x = rep("B", 2)),
C = tibble(x = 0:iter))
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的等高线图。
下面附有示例代码。输出是一个带有标签和警告消息的空图 -
1: stat_contour(): Zero contours were generated
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决它吗?
library(tidyverse)
# x and y are generated from uniform random distribution
x <- runif(1000, min = -5, max = 5)
y <- runif(1000, min = -5, max = 5)
z <- x^2 + y^2
tbl <- tibble(x, y, z)
ggplot(data = tbl,
aes(x = x,
y = y, …Run Code Online (Sandbox Code Playgroud) 如果其值之一是 ,如何删除整个组NA。对于 ex-删除categoryB 因为它包含NA.
library(dplyr)
tbl = tibble(category = c("A", "A", "B", "B"),
values = c(2, 3, 1, NA))
Run Code Online (Sandbox Code Playgroud) 下面是生成两个直方图的代码。但由于重叠严重,很难清楚地看到每个分布。
我怎样才能只绘制每个直方图的较粗轮廓并删除垂直线/条。
理想的直方图应该是这样的 -
library(tidyverse)
A <- rnorm(n = 1000, mean = 0, sd = 1)
B <- rnorm(n = 1000, mean = 0.1, sd = 1.3)
tbl <- tibble(A, B) %>%
# pivot longer
pivot_longer(cols = everything(),
names_to = "Distributions",
values_to = "values")
ggplot(data = tbl,
aes(x = values,
col = Distributions,
fill = Distributions)) +
geom_histogram(bins = 50,
alpha = 0.3,
position = "identity") +
theme_bw()
Run Code Online (Sandbox Code Playgroud) 有没有办法并排绘制两个县(不改变实际比例)来比较它们的大小。
我希望并排绘制圣地亚哥和圣克拉拉,以展示它们的实际大小。
谢谢
library(tigris)
library(ggplot2)
san_diego <- county_subdivisions(state = "CA", county = "San Diego County", cb = TRUE, year = NULL)
santa_clara <- county_subdivisions(state = "CA", county = "Santa Clara County", cb = TRUE, year = NULL)
gg_san_diego <- ggplot() +
geom_sf(data = san_diego,
color="black",
fill="white",
size=0.25)
gg_santa_clara <- ggplot() +
geom_sf(data = santa_clara,
color="black",
fill="white",
size=0.25)
gg_san_diego
gg_santa_clara
Run Code Online (Sandbox Code Playgroud)