我无法在R上安装"sf"软件包.似乎gdal存在问题.不知道如何解决它.
> install.packages("sf")
There is a binary version available but the source version is later:
binary source needs_compilation
sf 0.4-3 0.5-1 TRUE
Do you want to install from sources the package which needs compilation?
y/n: y
installing the source package ‘sf’
trying URL 'https://cran.rstudio.com/src/contrib/sf_0.5-1.tar.gz'
Content type 'application/x-gzip' length 4073881 bytes (3.9 MB)
==================================================
downloaded 3.9 MB
* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
configure: CC: clang
configure: CXX: clang++
checking for gdal-config... …Run Code Online (Sandbox Code Playgroud) 我正在尝试为pandoc添加自定义乳胶模板
我知道pandoc模板会进入 ~/.pandoc/templates
我通过输入确认了pandoc目录位置pandoc --v- 它说pandoc在~/.pandoc
但是当我这样做时cd ~/.pandoc:
-bash: cd: /Users/[Name]/.pandoc: No such file or directory
Run Code Online (Sandbox Code Playgroud)
根据pandoc手册页,我可以为pandoc数据文件设置不同的路径--data-dir=DIRECTORY,但是当我尝试以这种方式构建文件时,例如
pandoc file.md -o file.pdf --data-dir=~/Library/texmf/tex/latex --template=mytemplate.latex
Run Code Online (Sandbox Code Playgroud)
它会引发错误
pandoc: Could not find data file templates/mytemplate.latex
Run Code Online (Sandbox Code Playgroud)
我假设这意味着忽略数据目录命令.
为什么我不能访问我的pandoc目录?
假设您想要使用计算机现代字体(如 Latex 中所示)用于最新版本 RStudio(版本 0.98.1091)中生成的 knitr 文档。
因此,您上网查找源代码,并在您根据 Package Vignettes 提供的样式表修改的 .css 样式表中使用它:
@font-face {
font-family: 'Computer Modern Concrete';
src: url('cmunorm.eot');
src: url('cmunorm.eot?#iefix') format('embedded-opentype'),
url('cmunorm.woff') format('woff'),
url('cmunorm.ttf') format('truetype'),
url('cmunorm.svg#cmunorm') format('svg');
font-weight: normal;
font-style: normal;
}
body {
background-color: #fff;
margin: auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: 'Computer Modern Concrete';
font-size: 15px;
line-height: 1.10;
}
Run Code Online (Sandbox Code Playgroud)
并在 YAML 中调用样式表:
---
title: "CSS for dummies"
author: "This idiot"
date: "December 2014"
output:
html_document:
theme: null
highlight: null …Run Code Online (Sandbox Code Playgroud) Lyx和Latex使用.eps图像精彩地工作.但是当我从Rstudio导出带有平滑曲线的散点图时,这些点会丢失,并且只会使用曲线传递绘图.
我尝试过的两种保存方法是:
在Rstudio中,从图像字段的下拉菜单中选择"导出",然后另存为.eps.有趣的是,情节在Rstudio预览中应该显示.
前言积代码与setEPS()随后postscript(),将具有所需尺寸等,随后使用积呼叫library(ggplot2),例如ggplot().
起初我认为问题可能在其他地方.但后来我在Mathematica中保存了一个.eps并没有问题.
我在互联网上偷窥,发现在R中保存.eps的其他问题,但没有一个处理丢失的信息.
到底发生了什么?
我应该提一下.在Lyx中的.eps成像器渲染比任何其他格式都要好,所以我坚持使用.eps.
非常感谢你的投入,我还不能投票给他们.
编辑
据我所知,由于EPS无法保持透明度,因此这个问题是死路一条.(见评论.)根据要求,我发布了突出问题的代码.
说你有数据data <- data.frame(replicate(2,rnorm(1000))).你想绘制它们,但有很多点,所以你添加一个透明度参数.此外,还可以添加具有置信区间的拟合线.你的代码是:
ggplot(data = data, aes(x=X1, y=X2)) +
geom_point(alpha=0.4) +
stat_smooth(se=T, method="lm")
Run Code Online (Sandbox Code Playgroud)
看起来不错.但是,如果您尝试将绘图保存为EPS,则稍后打开保存文件时所看到的只是一个空的绘图对象,除了蓝色拟合线.
教训是,如果你坚持使用EPS,你必须关闭透明带.在这种情况下,设置alpha=1(或只是不包括它)和se=FALSE.
可以使用 将文本添加到ggplot对象annotate()。但是,我无法弄清楚如何打印星号,因为据我所知,星号用于解析。
这是一个例子。假设我运行了一个非参数检验,我想打印检验统计量,其显着性水平以星为单位。不幸的是,这不起作用:
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color=Species)) +
geom_point() +
annotate('text', x = 7, y = 4, label="chi^2 == 2.50***", parse=TRUE)
Error in parse(text = as.character(lab)) : <text>:1:16: unexpected '*'
1: chi^2 == 2.50***
Run Code Online (Sandbox Code Playgroud)
在绘图对象之外定义标签 - 例如lab <- paste0("chi^2 == 2.5","***", sep=""),然后调用annotate('text', x = 7, y = 4, label=lab, parse=TRUE)- 也不起作用。
星号可以和 一起使用annotate()吗?
编辑对不起,我忽略了我想要编译希腊字母。理想情况下,文本将显示为 $$chi^2 = 2.50***$$
我有一个如下所示的数据框:
我想遍历每一行并打印非NaN条目的[i,j]位置.在这里,循环理想地打印"G56"和"G51".
到目前为止,我已经创建了一个T/F数据帧,将所有非NaN记录为True:
df_na = df.notnull()
Run Code Online (Sandbox Code Playgroud)
我可以得到任何特鲁斯的行索引:
for index, row in df_na.iterrows():
if row.any() == True:
print(index)
Run Code Online (Sandbox Code Playgroud)
但我无法得到列名.(我也关注这种方法,因为iterrows()比itertuples()慢.
尝试整合正态分布
import numpy as np
import scipy
Run Code Online (Sandbox Code Playgroud)
这不起作用,会引发类型错误:
def f_np(x):
return np.random.normal(size=x)
integrate.quad(f_manual, -np.inf, np.inf)
mtrand.pyx in numpy.random.mtrand.RandomState.normal()
_common.pyx in numpy.random._common.cont()
TypeError: 'float' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)
但如果我手动输入pdf,它就会起作用:
def f_manual(x):
return 1/(1 * np.sqrt(2 * np.pi)) * np.exp(-(x - 0)**2 / (2 * 1**2) )
integrate.quad(f_manual, -np.inf, np.inf)
(0.9999999999999997, 1.017819145094224e-08)
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
我有来自以这种格式导出的实验的聊天记录:
df = data.frame(
subject = c("string",1,2,3,"string", 2, 3, "string", 1,1,3,4),
text = c(rep("blah blah blah", 12)),
period = c(rep("NA", 12))
)
> head(df)
subject text period
1 string blah blah blah NA
2 1 blah blah blah NA
3 2 blah blah blah NA
4 3 blah blah blah NA
5 string blah blah blah NA
6 2 blah blah blah NA
Run Code Online (Sandbox Code Playgroud)
其中"string"是整个列中重复的一些标识符文本.
我想写一个函数,a)识别subject列中的字符模式,b)根据period模式的每个实例分配一个值.
例如,我知道我可以通过运行实现第一部分
> grepl("s+", df$subject, perl = T)
[1] TRUE FALSE FALSE …Run Code Online (Sandbox Code Playgroud)