我有一个dataframe
带有箭头坐标的:
arrows = data.frame(direction = factor(c("forward", "backward", "backward")),
x = c(0, 0, 0),
xend = c(1, 1, 1),
y = c(1, 1.2, 1.1),
yend = c(1, 1.2, 1.1))
Run Code Online (Sandbox Code Playgroud)
我想使用这些数据来绘制箭头 - 有些是向前的,反之亦然。
到目前为止我尝试过:
library(ggplot2)
ggplot() +
geom_segment(data = arrows,
aes(x, y, xend = xend, yend = yend, col = direction),
arrow = arrow(length = unit(0.3, "cm"), type = "closed", ends = c("last", "first")))
Run Code Online (Sandbox Code Playgroud)
其产生:
我想在这个图中解决两个问题:
我如何确保ggplot
“理解”哪个情节是“向前”和“向后”,以便为他们提供正确的图例?
如何更改图例,使其显示前进方向,并带有向前的箭头和向后的向后箭头?
我想绘制 3 个正多边形 - 正方形(4 条边)、六边形(6 条边)和十二边形(12 条边),其方式与下图类似:
到目前为止,我一直在对ggforce
包进行硬编码以实现我的目标:
library(ggplot2)
library(ggforce)
df = data.frame(name = c("dodecagon", "square", "hexagon"),
x0 = c(0.5, 0.5, 0.63),
y0 = c(0.5, 0.745, 0.74),
sides = c(12, 4, 6),
angle = c(0, 0, -0.5),
r = c(0.2, 0.07, 0.09))
ggplot(data = df) +
geom_regon(aes(x0 = x0, y0 = y0, sides = sides, angle = angle, r = r, fill = name)) +
coord_fixed(xlim = c(0, 1), ylim = c(0, 1))
Run Code Online (Sandbox Code Playgroud)
其产生:
正如您所看到的,多边形没有很好地对齐,并且需要非常长的时间才能真正实现我想要实现的目标。
本质上,我想要一个函数,它以十二边形(12 边多边形)的数量作为参数,并在十二边形周围绘制正方形(4 …
在我的一份文件yaml
中:quarto
---\ntitle: "Hey!"\nauthor:\n - name: Birdy Bird\n affiliations:\n - University of Birds\n - University of Hummingbirds\nformat: pdf\neditor: visual\n---\n
Run Code Online (Sandbox Code Playgroud)\n当我使用 IDE 渲染此文件时Rstudio
,我得到:
我期待他们的数字的从属关系(例如 1、2 作为上标)会出现在某个地方。
\nR版本:
\n> sessionInfo()\nR version 4.2.2 (2022-10-31)\nPlatform: aarch64-apple-darwin20 (64-bit)\nRunning under: macOS Ventura 13.1\n\nMatrix products: default\nLAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib\n\nlocale:\n[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8\n\nattached base packages:\n[1] stats graphics grDevices utils datasets methods base \n\nloaded via a namespace (and not attached):\n[1] compiler_4.2.2 tools_4.2.2 \n
Run Code Online (Sandbox Code Playgroud)\nRstudio版本
\n> rstudioapi::versionInfo()\n$citation\n\nTo cite RStudio in publications …
Run Code Online (Sandbox Code Playgroud) 代码:
cr_journals(issn=c('1803-2427','2326-4225'))
Run Code Online (Sandbox Code Playgroud)
结果:
Error in cr_GET(endpoint = path, args, todf = FALSE, parse = TRUE, ...) :
res$response_headers$`content-type` == "application/json;charset=UTF-8" is not TRUE
Run Code Online (Sandbox Code Playgroud)
不知何故,RCROSSREF API 不会突然工作,并返回一个错误消息,如上所述,用于一个简单的查询,它之前工作得很好,现在我认为可能是我超出了限制,或者 API 方面发生了一些事情。
有谁知道如何解决这样的问题?
我想m^2 m^-2
使用gganimate
. 例如,当我只使用它时,下面给了我我想要的输出ggplot2
:
library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
labs(title = "Hp" ~ m^2 ~ m^-2)
Run Code Online (Sandbox Code Playgroud)
但是,当我执行以下操作时,gganimate
我没有得到 Hp 的变化值,但是{closest_state}
library(gganimate)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
transition_states(hp) +
labs(title = expression('Hp = {closest_state}' ~ m^2 ~ m^-2))
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题?
我正在Rstudio server
远程服务器上使用,并且已经安装了一些软件包。
当我尝试加载类似raster
或terra
using 之类的库时Rstudio server
,出现错误:
> library(terra)\n\nError: package or namespace load failed for \xe2\x80\x98terra\xe2\x80\x99 in dyn.load(file, DLLpath = DLLpath, ...):\n unable to load shared object '/home/pearless/R/x86_64-pc-linux-gnu-library/4.1/terra/libs/terra.so':\n libproj.so.15: cannot open shared object file: No such file or directory\n\n> library(raster)\n\nError: package or namespace load failed for \xe2\x80\x98raster\xe2\x80\x99 in dyn.load(file, DLLpath = DLLpath, ...):\n unable to load shared object '/home/pearless/R/x86_64-pc-linux-gnu-library/4.1/terra/libs/terra.so':\n libproj.so.15: cannot open shared object file: No such file or directory\n
Run Code Online (Sandbox Code Playgroud)\n请注意,使用 …
我想在 bookdown 中写的论文中包含我的导师的姓名、课程名称等。我特别希望这些信息位于不同的行中。到目前为止,我已经在 yaml 中尝试过:
---
title: "Term Paper Title"
author:
- "Bird"
- "Supervisor: Hummingbird"
- "Course: Ornithology"
- "University: XXX State University"
date: "Summer Semester: 2021"
site: bookdown::bookdown_site
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
documentclass: book
classoption: openany
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
mainfont: Times New Roman
fontsize: 12pt
geometry: "left=3cm, right=2cm, top=2.5cm, bottom=2.5cm"
linestretch: 1.5
toc-depth: 1
secnumdepth: 1
---
Run Code Online (Sandbox Code Playgroud)
结果如下:
我必须使用物理公式来实现一些模拟。在一个公式中,有许多变量。我想用 100 个样本改变这些变量。对于每个样本,我必须使用所有组合进行计算。简化的 for 循环更好地解释了我想要做什么:
set.seed(3)
a = rnorm(100)
b = rnorm(100)
c = rnorm(100)
d = rnorm(100)
f = rnorm(100)
for (a in 1:length(a)) {
for (b in 1:length(b)) {
for (c in 1:length(c)) {
for (d in 1:length(d)) {
for (f in 1:length(f)) {
value = a + b / c * d - f # for illustrative purposes only
# ....
# ... then I append the value to a vector etc.
}
}
}
}
} …
Run Code Online (Sandbox Code Playgroud) readr
包中有一个名为的函数parse_number
,它返回 a 中的数字string
:
readr::parse_number("Hello 2022!")
[1] 2022
Run Code Online (Sandbox Code Playgroud)
是否有类似的方法从 a 返回日期string
?有readr
一个名为的函数parse_date
,但它做了一些不同的事情:
readr::parse_date("X2018-01-11_poland")
Warning: 1 parsing failure.
row col expected actual
1 -- date like X2018-01-11_poland
[1] NA
Run Code Online (Sandbox Code Playgroud)
期望的输出:
# the raw string is "X2018-01-11_poland"
2018-01-11
Run Code Online (Sandbox Code Playgroud)
PS 我对使用正则表达式执行此操作不感兴趣。
这有效:
mtcars[, c("mpg"), drop = F]
mpg
Mazda RX4 21.0
Mazda RX4 Wag 21.0
Datsun 710 22.8
Hornet 4 Drive 21.4
Hornet Sportabout 18.7
Valiant 18.1
Duster 360 14.3
Merc 240D 24.4
Merc 230 22.8
Merc 280 19.2
Merc 280C 17.8
Merc 450SE 16.4
Merc 450SL 17.3
Merc 450SLC 15.2
Cadillac Fleetwood 10.4
Lincoln Continental 10.4
Chrysler Imperial 14.7
Fiat 128 32.4
Honda Civic 30.4
Toyota Corolla 33.9
Toyota Corona 21.5
Dodge Challenger 15.5
AMC Javelin 15.2
Camaro Z28 13.3 …
Run Code Online (Sandbox Code Playgroud)