小编San*_*ang的帖子

R图的传说中的多个bquote项

以下作品,(复制并粘贴到R中)

a=123
plot(1,1)
legend('bottomleft',legend=bquote(theta == .(a)))
Run Code Online (Sandbox Code Playgroud)

我想在图例中有多个项目.全部都带有希腊字母.举个简单的例子,如果我重复两次这个项目,代码就不再起作用了

a=123
plot(1,1)
legend('bottomleft',legend=c(bquote(theta == .(a)),bquote(theta == .(a))))
Run Code Online (Sandbox Code Playgroud)

我尝试过更复杂的表达式,但它们都没有用.

任何帮助将不胜感激.

plot r legend plotmath

11
推荐指数
1
解决办法
7187
查看次数

是Boost Library的加权中位数被打破了吗?

我承认我不是C++的专家.

我正在寻找一种快速计算加权中位数的方法,Boost似乎有.但似乎我无法使其发挥作用.

#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/weighted_median.hpp>
using namespace boost::accumulators;    

int main()
{
  // Define an accumulator set
  accumulator_set<double, stats<tag::median > > acc1;
  accumulator_set<double, stats<tag::median >, float> acc2;

  // push in some data ...
  acc1(0.1);
  acc1(0.2);
  acc1(0.3);
  acc1(0.4);
  acc1(0.5);
  acc1(0.6);

  acc2(0.1, weight=0.);
  acc2(0.2, weight=0.);
  acc2(0.3, weight=0.);
  acc2(0.4, weight=1.);
  acc2(0.5, weight=1.);
  acc2(0.6, weight=1.);

  // Display the results ...
  std::cout << "         Median: " << median(acc1) << std::endl;
  std::cout << "Weighted Median: " << median(acc2) << std::endl; …
Run Code Online (Sandbox Code Playgroud)

c++ statistics boost

5
推荐指数
2
解决办法
2664
查看次数

ggplot2数字缓存与knitr

我有以下代码,它按原样工作,但当cache = T时不起作用更改设备没有区别(默认,tikz,cairo)

% \SweaveOpts{fig.path=cache/figure/plot-,cache.path=cache/data/data-,fig.align=center,external=TRUE,fig.show=hold,cache=TRUE,echo=FALSE,pdfcrop=TRUE}

<<message=F,fig.width=9,fig.height=6,out.width=\textwidth,cache=F>>=
grid.newpage()
pushViewport(viewport(layout = grid.layout(2,9))) 

d <- ncol(rTSc)
p <- ggplot(melt(coveig),aes(1:d,value,group=variable,col=variable))  + 
  geom_line() + labs(x="index",y="eigenvalue") + 
  opts(legend.position = "none")  
print(p, vp=viewport(layout.pos.row=1,layout.pos.col=1:4))
p <- ggplot(melt(coreig),aes(1:d,value,group=variable,col=variable)) + 
  geom_line() + labs(x="index",y="eigenvalue")
print(p, vp=viewport(layout.pos.row=1,layout.pos.col=5:9))

p <- ggplot(melt(coveig.cs),aes(1:d,value,group=variable,col=variable)) + 
  geom_line() + labs(x="index",y="cumulative eigenvalue") + 
  opts(legend.position = "none")
print(p, vp=viewport(layout.pos.row=2,layout.pos.col=1:4))
p <- ggplot(melt(coreig.cs),aes(1:d,value,group=variable,col=variable)) + 
  geom_line() + labs(x="index",y="cumulative eigenvalue")
print(p, vp=viewport(layout.pos.row=2,layout.pos.col=5:9))
@ 
Run Code Online (Sandbox Code Playgroud)

为什么会这样呢?有任何想法吗?

谢谢!

r ggplot2 knitr

4
推荐指数
1
解决办法
1573
查看次数

在自定义R程序包中使用“ Matrix”程序包方法

以下代码是自定义R包中的函数。

#' @import Matrix
#' @export
asdf <- function(){
    u <- Matrix(0,5,5)
    rowSums(u)
}
Run Code Online (Sandbox Code Playgroud)

当我加载并执行程序包时,得到以下输出。

> library(devtools); document(clean=TRUE); load_all()
Loading required package: roxygen2
Updating gm documentation
Loading gm
Loading required namespace: Matrix
Loading required package: Matrix
Writing gm.generate.Rd
Loading gm
> asdf
function(){
    u <- Matrix(0,5,5)
    rowSums(u)
}
<environment: namespace:gm>
>
> asdf()
Error in rowSums(u) (from tmp.R#5) : 'x' must be an array of at least two dimensions
Run Code Online (Sandbox Code Playgroud)

因此,即使已加载rowSumsMatrix包,即使Matrix包已导入Matrix包,也不会分派Matrix包NAMESPACE

export(asdf)
import(Matrix)
Run Code Online (Sandbox Code Playgroud)

在全局环境中,确实已加载Matrix包,并且rowSums功能可用。

> …
Run Code Online (Sandbox Code Playgroud)

r sparse-matrix

4
推荐指数
1
解决办法
439
查看次数

在Emacs + AUCtex下一次性命令编织和latexmk

我想使用一个AUCtex命令编织AND latexmk Knitr文档.我不知道如何在lisp中编码,而网络搜索没有发现这样的事情.

我有一些接近的东西.需要为latexmk更改文件的扩展名.任何帮助将不胜感激.

以下行是我的.emacs文件.

(add-hook 'LaTeX-mode-hook (lambda () (push '
  ("KnitrLaTeX" "Rscript -e \"library(knitr)\; knit('%s')\" && latexmk -pdf %s" 
   TeX-run-TeX nil t :help "Run knitr and latexmk on file") 
   TeX-command-list)))
Run Code Online (Sandbox Code Playgroud)

当我运行时C-c C-c (KnitrLaTeX),emacs运行以下命令:

Running `KnitrLaTeX' on `slides.Rnw' with ``Rscript -e "library(knitr); knit('slides.Rnw')" && latexmk -pdf slides.Rnw''
Run Code Online (Sandbox Code Playgroud)

哪个错了.它应该读"... && latexmk -pdf slides.tex"

提前致谢.

emacs auctex latexmk knitr

3
推荐指数
1
解决办法
711
查看次数

标签 统计

r ×3

knitr ×2

auctex ×1

boost ×1

c++ ×1

emacs ×1

ggplot2 ×1

latexmk ×1

legend ×1

plot ×1

plotmath ×1

sparse-matrix ×1

statistics ×1