如何在格子轮廓图中为颜色键添加标题?
library(lattice)
contourplot(volcano, region=T, main='title')
Run Code Online (Sandbox Code Playgroud)
我搜索了文档,没有看到任何关于colorkey参数的文本或标题或任何其他contourplot/levelplot选项.
我有一个简单的表,其中包含我想要从R导出到Latex的维度名称.我正在寻找一种直接的方法,不需要在乳胶中进行额外的编辑.这似乎应该很容易,但我在这个主题上找到了许多其他未解决的问题.
我试过在这篇文章之后使用Hmisc latex命令.它产生OP状态,但问题仍然没有得到解决. 这篇文章有一堆表格选项,但我没有看到维度名称被解决.! LaTeX Error: Illegal character in array arg.
R-代码
library(Hmisc)
latex(table(state.division, state.region), rowlabel = "X", collabel = "Y", file = "")
Run Code Online (Sandbox Code Playgroud)
产量
%latex.default(table(state.division, state.region), rowlabel = "X", collabel = "Y", file = "")%
\begin{table}[!tbp]
\begin{center}
\begin{tabular}{lrrrr}
\hline\hline
\multicolumn{1}{l}{X}&\multicolumn{1}{Y}{Northeast}&\multicolumn{1}{l}{South}&\multicolumn{1}{Y}{North Central}&\multicolumn{1}{l}{West}\tabularnewline
\hline
New England&$6$&$0$&$0$&$0$\tabularnewline
Middle Atlantic&$3$&$0$&$0$&$0$\tabularnewline
South Atlantic&$0$&$8$&$0$&$0$\tabularnewline
East South Central&$0$&$4$&$0$&$0$\tabularnewline
West South Central&$0$&$4$&$0$&$0$\tabularnewline
East North Central&$0$&$0$&$5$&$0$\tabularnewline
West North Central&$0$&$0$&$7$&$0$\tabularnewline
Mountain&$0$&$0$&$0$&$8$\tabularnewline
Pacific&$0$&$0$&$0$&$5$\tabularnewline
\hline
\end{tabular}\end{center}
\end{table}
Run Code Online (Sandbox Code Playgroud)
乳胶渲染后的错误消息
Errors:
./test.tex:9: LaTeX Error: Illegal character in …Run Code Online (Sandbox Code Playgroud) 使用pandoc渲染Microsoft Word文档.字体似乎默认为标题的Calibri和正文的Cambri.目标是让文件使用Arial或Times罗马字体.
我不想触摸/编辑/与word中的文件有任何关系.
如何从多标记源或pandoc调用中设置将在Word™中使用的字体?
Pandoc命令:
pandoc -s my_markdown.txt -o whycambriafont.docx
Run Code Online (Sandbox Code Playgroud)
这个问题:pandoc生成的docx错过了方程式中的斜体变量,显示了一种通过创建zip然后编辑样式文件来编辑字体样式的方法,但它是一个kludge.
在格式化日期时,使用%m=month、%y=day和%d=day是显而易见且容易记住的,但是in代表什么?b%b
换句话说,为什么要%b注明月份的缩写呢?这只是简单地通过字母表来描述各种术语还是有有意义的链接?
我发现了很多描述该格式的网站(例如 W3Schools,但我一直无法找到该%b术语的词源。
目标是显示重叠的直方图,但我想避免使用 alpha 调整,以便颜色保持明亮。
有没有办法在不调整 alpha arg 的情况下做到这一点?
目标是显示如下所示的颜色:
hist(rnorm(mean=10, n = 1000), col='blue')
hist(rnorm(mean=11, n = 1000), col='red', add=T)
Run Code Online (Sandbox Code Playgroud)
但也要显示重叠区域,如下所示
hist(rnorm(mean=10, n = 1000), col='blue')
hist(rnorm(mean=11, n = 1000), col=rgb(1,0,0,0.5), add=T)
Run Code Online (Sandbox Code Playgroud)
类似的问题并没有完全解决透明度问题:
我对密度和使用其他图形包(例如格子、ggplot2 等)没问题。
编辑:我想要填充地块并且相交区域是不同的颜色(例如红色和蓝色相交的紫色)。
开始使用magrittr管道运算符,如果可以在单个流程中创建两个数据框,那就很奇怪了.例如,生成用于绘图的非聚合数据框和用于订购因子的聚合数据框(聚合排序示例)将是有帮助的.
这是一个相当人为的例子,说明了这个问题:
library(dplyr)
library(tidyr)
library(magrittr)
library(ggplot2) # msleep
vore_count <-
na.exclude(msleep) %>%
group_by(vore, order) %>%
summarise(count = n()) %>%
ungroup()
agg <- vore_count %>%
spread(vore, count)
Run Code Online (Sandbox Code Playgroud)
既可以vore_count 与 agg在同一个流程中产生的?
我尝试了以下(以及使用%T>%),这显然不起作用.
vore_count <-
na.exclude(msleep) %>%
group_by(vore, order) %>%
summarise(count = n()) %>%
ungroup() %>%
agg <- spread(vore, count)
Run Code Online (Sandbox Code Playgroud) 我可以从IDE(Rstudio)中获取R脚本,但不能从命令行调用中获取.有没有办法做到这一点,而无需提供完整的路径?
我想要源的文件位于父目录中.
这有效:
source('../myfile.R') #in a call from Rstudio
Run Code Online (Sandbox Code Playgroud)
但是,这不是:
> Rscript filethatsources_myfile.R
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file '../myfile.R': No such file or directory
Execution halted
Run Code Online (Sandbox Code Playgroud)
这似乎应该很简单,但......
编辑:我正在使用GNU bash,版本3.2.53(1)-release(x86_64-apple-darwin13)
目标:将数据帧随机分成3个样本.
这是一个笨重的解决方案:
allrows <- 1:nrow(mtcars)
set.seed(7)
trainrows <- sample(allrows, replace = F, size = 0.6*length(allrows))
test_cvrows <- allrows[-trainrows]
testrows <- sample(test_cvrows, replace=F, size = 0.5*length(test_cvrows))
cvrows <- test_cvrows[-which(test_cvrows %in% testrows)]
train <- mtcars[trainrows,]
test <- mtcars[testrows,]
cvr <- mtcars[cvrows,]
Run Code Online (Sandbox Code Playgroud)
必须有一些更容易的东西,也许在一个包中. dplyr有sample_frac功能,但似乎针对单个样本,而不是分成多个.
关闭,但不是这个问题的答案: R中有多个概率的随机样本
通常我使用readxl包(非常好)来读取excel文件:
read_excel(path = 'ihateexcel.xls', sheet = 1)
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试读取加密的.xls文件,会话将基本冻结.显然不希望将文件保存为.csv,因为我将丢失加密或必须使用其他加密.似乎无法在其他软件包中找到此功能xlsx.
如何读取在Excel中加密的.xls文件?
给定一组数据,我如何确定新数据点是高于还是低于连接点的线.
例如,如何确定显示的红点是否在线的上方或下方(没有目视检查)?
我想在这些点上找到一条确切的线.基本上连接点,并需要适合能够使用线上的任何点作为比较器.
到目前为止,我已经尝试将各种样条拟合到数据中,但它仍然有点过于平滑.我真的在寻找一个完全适合数据,尖角和所有.
我已经尝试了一个自然样条曲线(以及smooth.splines),但是不能完全得到精确/足够的拟合:
plot(df$lowerx, df$lowery, type='b', xlab='x', ylab='y', pch=21, bg='steel blue')
myspline <- splinefun(df$lowerx, df$lowery, method='natural')
curve(myspline, add=T, from = 0, to=140, n = 100, col='green')
Run Code Online (Sandbox Code Playgroud)
我认为一旦我得到合适的权利,它将直接用它来确定点是在线之上还是之下(例如使用预测或函数),但我需要帮助.
也完全欢迎另一种方法.
数据:
df <- structure(list(lowerx = c(11.791, 18.073, 23.833, 35.875, 39.638, 44.153, 59.206, 71.498, 83.289, 95.091, 119.676, 131.467, 143.76), lowery = c(5.205, 5.89, 6.233, 9.041, 10, 10.342, 12.603, 13.493, 14.658, 15.274, 15.89, 15.616, 15.342)), .Names = c("lowerx", "lowery"), class = "data.frame", row.names = c(NA, -13L))
Run Code Online (Sandbox Code Playgroud) 向绘图添加刻度(比默认值更多的刻度)时,如何
grid()将网格与刻度线对齐?
plot(1:10,las=1,xaxp = c(0, 10, 10),xlim=c(0,10), ylim=c(0,10))
grid(lwd=2, nx=10, ny=10)
Run Code Online (Sandbox Code Playgroud)
尝试更改了网格中arg的xlim不同数字nx(单元格数),但网格根本没有排列.
相关,但不回答问题: 在R,bReeze包中对齐网格线
相关,并使用解决方法: 将网格与刻度线对齐
变通方法是最有效的选择吗?
目标:将日期对象转换为星期日的日期; 它们仍然应该作为日期对象
例如,今天将转换为2016-10-16,明天将转换为相同.
样本数据:
library(lubridate)
dt <- Sys.Date()-days(1:20)
"2016-10-17" "2016-10-16" "2016-10-15" "2016-10-14" "2016-10-13" "2016-10-12" "2016-10-11"
"2016-10-10" "2016-10-09" "2016-10-08" "2016-10-07" "2016-10-06" "2016-10-05"
"2016-10-04" "2016-10-03" "2016-10-02"
Run Code Online (Sandbox Code Playgroud)
预期产量:
"2016-10-16" "2016-10-16" "2016-10-09" "2016-10-09" "2016-10-09" "2016-10-09" "2016-10-09"
"2016-10-09" "2016-10-09" "2016-10-02" "2016-10-02" "2016-10-02" "2016-10-02"
"2016-10-02" "2016-10-02" "2016-10-02"
Run Code Online (Sandbox Code Playgroud)
我试着玩lubridate,zoo和xts包和strptime,但没有相当的供应需求.yearweek MySQL中的函数正是我想要的(注意:包sqldf没有那个功能).
这似乎已经有了答案,但搜索没有运气; C++,javascript和Ruby,但R中没有任何内容.