YSU

  •  
  • 2019年8月3日
  • 注册于 2010年9月17日
  • 嗯, 复试在即, 祝你顺利过关, 进入喜欢的学校.
  • reorder is what you need for this purpose.
    ggplot(fata_top15, aes(x=reorder(EVTYPE, all.fata), y=all.fata)) +
    geom_bar()
  • 老大现在不来这儿了? :-(
  • 有一个现成的pdf文件, 如何在用knitr写报告时直接插入这个文件?谢了!
  • [未知用户]
    See below,
    http://www.stat.ncsu.edu/people/davidian/courses/st732/notes/
  • 回复 第4楼 的 yanlinlin82:

    wikipedia???

    其它学科不知道, 但是: Wikipedia, the online encyclopaedia, contains errors in nine out of 10 of its health entries, and should be treated with caution, a study has said.

    http://www.bbc.com/news/health-27586356

  • 谁能提示一下?

  • Another trick.

    <br />
    dat$names1 <- paste(dat$names, rep(1:nrow(dat)), sep="-")</p>
    <p>p1 <- ggplot(dat, aes(x=reorder(names1, quantity), y=quantity))+<br />
      geom_bar(stat='identity')+<br />
      facet_grid(~items, scales="free")+<br />
      scale_x_discrete(breaks=dat$names1, labels=dat$names)</p>
    <p>
    </p>
  • 回复 第5楼 的 Torenable:

    "reorder" function can change the levels of factor "names" according to the numerical sequence of "quantity" on the fly.

    <br />
    tmp <- subset(data, items == "earprotector", c(names, quantity))<br />
    p1 <- ggplot(tmp, aes(x = reorder(names, quantity), y = quantity)) +<br />
      geom_bar(stat = 'identity')<br />
    
    </p>
  • 回复 第5楼 的 273275395:

    Not really, see below.

    <br />
    dat <- as.data.frame(matrix(rnorm(10), nrow=2))<br />
    dat<br />
             V1         V2         V3        V4         V5<br />
    1  3.526979 -1.2938406 0.02296229 0.6783160 -0.2186516<br />
    2 -1.174209 -0.5561583 0.32545627 0.7988773 -1.3914670</p>
    <p>dat[,sample(1:ncol(dat), 2)]<br />
              V2         V3<br />
    1 -1.2938406 0.02296229<br />
    2 -0.5561583 0.32545627<br />
    
    </p>
  • 回复 第3楼 的 273275395:

    Sample the row names, then use it to subset.

    <br />
    dat <- as.data.frame(matrix(rnorm(10), nrow=5))<br />
    dat<br />
              V1          V2<br />
    1 -0.6436334  1.45972325<br />
    2  0.7862687 -0.51203074<br />
    3 -0.3284080 -0.75884870<br />
    4 -1.1309293  0.02368129<br />
    5  1.1150183 -0.70088764</p>
    <p>dat[sample(row.names(dat), 2),]<br />
              V1         V2<br />
    4 -1.1309293 0.02368129<br />
    1 -0.6436334 1.45972325<br />
    
    </p>
  • <br />
    graph2 <- ggplot() +<br />
      geom_bar(data = growth,<br />
               aes(x = factor(day), y = mean, fill = group),<br />
               colour = "black", stat = "identity", position = "dodge") +<br />
      geom_errorbar(data = growth,<br />
                    aes(x = factor(day), ymax = mean + se, ymin = mean - se, fill = group),<br />
                    stat = "identity", position = "dodge")<br />
    
    </p>
  • like this?

    <br />
    > dat <- read.table("clipboard",as.is=T)<br />
    > dat<br />
      user_id brand_id visit_days type<br />
    1   19500     2257         85    1<br />
    2   19500     4949         85    1<br />
    3   19500     5086         80    5<br />
    4   19500     5086         83    1<br />
    5   19500     6148         85    2<br />
    6   19500     6148         86    1<br />
    > dat.m <- melt(dat, id.var=c("user_id", "brand_id", "visit_days"), measure.var=c("type"))<br />
    > dat.m<br />
      user_id brand_id visit_days variable value<br />
    1   19500     2257         85     type     1<br />
    2   19500     4949         85     type     1<br />
    3   19500     5086         80     type     5<br />
    4   19500     5086         83     type     1<br />
    5   19500     6148         85     type     2<br />
    6   19500     6148         86     type     1<br />
    > dat.c <- cast(dat.m, user_id + brand_id + variable ~ visit_days)<br />
    > dat.c<br />
      user_id brand_id variable 80 83 85 86<br />
    1   19500     2257     type NA NA  1 NA<br />
    2   19500     4949     type NA NA  1 NA<br />
    3   19500     5086     type  5  1 NA NA<br />
    4   19500     6148     type NA NA  2  1<br />
    
    </p>
  • 为了have head have tail,自己画个句号。

    的确是LaTex问题,有很多讨论和不少解决办法,其中之一是用caption这个package, 可以在\documentclass{article}后面加入

    <br />
    \usepackage{caption}<br />
    
    </p>
  • 自己顶一下。感觉是Latex问题。盼指点。

    一个Figure被分成很多页时,可能就有问题. 下面一个Figure分成了25页,就挂了。

    <br />
    \documentclass{article}<br />
    \begin{document}</p>
    <p><<test, echo=FALSE,fig.cap="asdf">>=<br />
    library(lattice)<br />
    dat <- data.frame(x = rnorm(100),<br />
                      y = rnorm (100),<br />
                      a = rep(1:50, ea = 2)<br />
                      )<br />
    xyplot(y~x|a,<br />
           data = dat,<br />
           layout = c(2, 1)<br />
           )<br />
    @</p>
    <p>\end{document}<br />
    
    </p>

    而分成10页时候,正常输出。

    <br />
    \documentclass{article}<br />
    \begin{document}</p>
    <p><<test, echo=FALSE,fig.cap="asdf">>=<br />
    library(lattice)<br />
    dat <- data.frame(x = rnorm(100),<br />
                      y = rnorm (100),<br />
                      a = rep(1:20, ea = 5)<br />
                      )<br />
    xyplot(y~x|a,<br />
           data = dat,<br />
           layout = c(2, 1)<br />
           )<br />
    @</p>
    <p>\end{document}<br />
    
    </p>
  • 我用Knitr 1.2.

    问题一: 如下一个Chunk里面有20张图时,就出错,前几张就会挤在一起,如把 ncol 改成5, 也就是说一个Chunk里面有5张图时,一切正常。

    问题二,我想把在同一个里面的20张图都赋予同一个 figure number, 比如"Figure 1",怎么解决?

    <br />
    \documentclass{article}<br />
    \begin{document}</p>
    <p><<test, echo=FALSE,fig.cap="asdf">>=<br />
    dat <- matrix(rnorm(100), ncol=20)<br />
    for(ii in 1:ncol(dat)){<br />
      plot(dat[,ii])<br />
    }<br />
    @</p>
    <p>\end{document}<br />
    
    </p>
  • 回复 第4楼 的 zggjtsgzczh:

    大一课程充斥着:马列,品德教育,军事理论,医学史... 以致美国导师看成绩单认为我是社会学专业[s:12],晕。

  • 回复 第3楼 的 superdesolator:

    在原来的code上稍微修改一下

    </p>
    <p>lm.velo<-lm(short.velocity~blood.glucose,data=thuesen)</p>
    <p>qplot(blood.glucose,short.velocity,data=thuesen)+geom_smooth(method="lm")</p>
    <p>fitted(lm.velo)<br />
    resid(lm.velo)</p>
    <p>pred.frame <- data.frame(blood.glucose=thuesen$blood.glucose)</p>
    <p>pp<-predict(lm.velo,int="p",<br />
                newdata=pred.frame,<br />
                interval ="prediction") ## note I changed here</p>
    <p>mydf<-data.frame(pred.frame,pp)<br />
    my.naexclude <- data.frame(thuesen,fitted=fitted(lm.velo),resid=resid(lm.velo))<br />
    my.naexclude <- my.naexclude[!is.na(my.naexclude$short.velocity),]</p>
    <p>## several changes within qplot<br />
    qplot(blood.glucose,short.velocity,data=my.naexclude)+<br />
        geom_smooth(method="lm", aes(fill="confidence"))+<br />
        geom_linerange(aes(ymin=fitted,ymax=short.velocity),<br />
                       data=my.naexclude,<br />
                       fullrange=T,<br />
                       colour="grey50")+<br />
        geom_ribbon(aes(x=blood.glucose,y=fit,ymin=lwr,ymax=upr, fill="prediction"),<br />
                    data=mydf,<br />
                    alpha=I(1/10))+<br />
        scale_fill_manual(values=c("blue", "green"),<br />
                          name="What_is_it",<br />
                          breaks=c("confidence", "prediction"),<br />
                          labels=c("Say_this", "Say_that"))</p>
    <p>
    </p>
  • MIfuns::reapply非常有用.

    <br />
    library(MIfuns)<br />
    dat <- read.table("clipboard", header = TRUE)<br />
    dat$MAX <- with(dat, reapply(value, year, max))<br />
    


    [data]

    year value MAX

    1 2000 123 345

    2 2000 345 345

    3 2001 124 456

    4 2001 456 456

    5 2002 125 567

    6 2002 567 567

    [/data]
    </p>
  • 去下面地址注册:

    http://www.rosaandco.com/webinarLeil.html