小编Aut*_*umn的帖子

使用knitr时如何旋转多个图块?

我正在使用带有情节的knitr.我想将其中一个旋转90度.例如:

\documentclass{article}

\begin{document}


<<cache=TRUE, echo=FALSE, message=FALSE, warning=FALSE, comment=NA, eval=TRUE, results=asis>>=

library("ggplot2")
library("gridExtra")

func <- function(data,x,y) {

  p1 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
  p2 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
  p3 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
  p4 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()

  grid.newpage() 
    pushViewport(viewport(width = .9, height = .9,layout = grid.layout(nrow=2, ncol=2)))
    print(p1,vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
    print(p2,vp = …
Run Code Online (Sandbox Code Playgroud)

r knitr

9
推荐指数
1
解决办法
3518
查看次数

如何改变grid.draw的位置

我正在安排ggplot2生成的图.我必须使用print打印出plot和grid.draw来显示图例.

示例代码:

p0 <- ggplot(data = iris, geom = 'blank',
         aes(y = Petal.Width, x = Petal.Length, color = Species)) + geom_point() +
      theme(axis.title.x = element_blank(),
            axis.title.y = element_blank(),
            legend.position = "none")

p1 <- ggplot(data = iris, geom = 'blank',
         aes(y = Petal.Length, x = Petal.Width, color = Species)) + geom_point() +
       theme(axis.title.x = element_blank(),
             axis.title.y = element_blank(),
             legend.position = "none")

g_legend <- function(a.gplot){
  tmp <- ggplot_gtable(ggplot_build(a.gplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)
}

p <- …
Run Code Online (Sandbox Code Playgroud)

r r-grid

8
推荐指数
2
解决办法
6128
查看次数

当标题是ggplot2中的变量时,如何更改标题标题的字体大小?

我正在使用ggplot2生成散点图.我把标题变成了变量,如何更改字体大小?代码如下:

library("ggplot2")
plotfunc <- function(x){
    x +
    geom_point() +
    geom_smooth(se = FALSE, method = "lm",  color = "blue", size = 1) +
    opts(title = plottitle,
           axis.title.x = theme_text(size = 8, colour = 'black'),
         axis.title.y = theme_text(size = 8, colour = 'black', angle = 90))
}

plottitle <- "This is Title"
p <- ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width))
plotfunc(p)
Run Code Online (Sandbox Code Playgroud)

我试过了

opts(title = plottitle (size = 10),...
Run Code Online (Sandbox Code Playgroud)

但是有一个错误:

Error in opts(title = plottitle(size = 10),
axis.title.x = theme_text(size …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

在 R 中使用子集时如何忽略大小写

在R中使用子集函数时如何忽略大小写?

eos91corr.data <- subset(test.data,select=c(c(X,Y,Z,W,T)))
Run Code Online (Sandbox Code Playgroud)

我想选择名称为 x,y,z,w,t 的列。我应该怎么办?

谢谢

r subset

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

如何在宏变量中存储变量的不同值

我有一个组宏变量,我想将其类放入宏变量中。例如:

%macro test(group=);
        proc freq data=foll;
        tables &group / out=freqtbl;
    run;
    proc sql;
        create table grp
         (grpid char(4));
        insert into grp
         values('a')
         values('b')
        ;
    quit;
    data freqtbl1;
        merge grp freqtbl;
    run;
    data freqtbl2;
        set freqtbl1;
        call symput(grpid,&group);
    run;    * &a is the first group, &b is the second group;
%mend;
Run Code Online (Sandbox Code Playgroud)

这适用于 2 个类,但如果有 3 个或 3 个以上类怎么办?

多谢。

macros sas

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

从字符串中提取多种类型的模式

我从字符串中提取多种类型的模式.例如,

"2013年3月25日上市25000,2010年4月5日售价10,250美元"

我想提取日期"03/25/2013"​​"4/5/2010"到矢量'日期',以及"25000""$ 10,250"到矢量金额.

text <- "Listed 03/25/2013 for 25000 and sold for $10,250 on 4/5/2010"
  # extract dates
dates <- str_extract_all(text,"\\d{1,2}\\/\\d{1,2}\\/\\d{4}")[[1]]
  # extract amounts
text2 <- as.character(gsub("\\d{1,2}\\/\\d{1,2}\\/\\d{4}", " ", text))
amountsdollar <- as.character(str_extract_all(text2,"\\$\\(?[0-9,.]+\\)?"))
text3 <- as.character(gsub("\\$\\(?[0-9,.]+\\)?", " ", text2))
amountsnum <- as.character(str_extract_all(text3,"\\(?[0-9,.]+\\)?"))
amounts <- as.vector(c(amountsdollar, amountsnum))
list(dates, amounts)
Run Code Online (Sandbox Code Playgroud)

但订单没有保留.有没有更好的方法呢?谢谢.

r

0
推荐指数
1
解决办法
549
查看次数

标签 统计

r ×5

ggplot2 ×1

knitr ×1

macros ×1

r-grid ×1

sas ×1

subset ×1