美文网首页
2020-05-26

2020-05-26

作者: 远方_fcf5 | 来源:发表于2020-05-27 00:12 被阅读0次

    ggplot2绘图:

    点状图

    data(mtcars)
    df <- mtcars[, c("mpg","cyl","wt")]
    dfcyl <- as.factor(dfcyl)转换
    head(df)

    1. ggplot(data=df, aes(x=mpg, y=wt))+
      geom_point()
    2. ggplot(data=df, aes(x=mpg, y=wt))+geom_point(color="blue", size=2, shape=23)

    面积图

    set.seed(1234)
    wdata <- data.frame(
    sex=factor(rep(c("F", "M"), each=200)),
    weight=c(rnorm(200, 55), rnorm(200, 58))
    )
    head(wdata)
    ggplot(wdata, aes(x=weight))+stat_density()
    对于每一种几何图形。ggplot2 基本都提供了 geom_()和 stat_()

    colsums()列求和
    rowsums()行求和
    rbind(),cbind()

    例如:
    dfx <- c(1,3,10,16,33,70,150)
    dfy <- c(5,8,18,20,45,90,200)
    df <- data.frame(dfx,dfy)
    colSums(df)
    rowSums(df)
    df$rowsum <- rowSums(df)
    df
    df[8,] <- colSums(df)
    df

    结果:

    dfx <- c(1,3,10,16,33,70,150)
    dfy <- c(5,8,18,20,45,90,200)
    df <- data.frame(dfx,dfy)
    colSums(df)
    dfx dfy
    283 386
    rowSums(df)
    [1] 6 11 28 36 78 160 350
    df$rowsum <- rowSums(df)
    df
    dfx dfy rowsum
    1 1 5 6
    2 3 8 11
    3 10 18 28
    4 16 20 36
    5 33 45 78
    6 70 90 160
    7 150 200 350
    8 283 386

    dfadd <- dfdfx+df$dfy

    df
    dfx dfy rowsum add
    1 1 5 6 6
    2 3 8 11 11
    3 10 18 28 28
    4 16 20 36 36
    5 33 45 78 78
    6 70 90 160 160
    7 150 200 350 350
    8 283 386 669 669


    Rstudio.png

    相关文章

      网友评论

          本文标题:2020-05-26

          本文链接:https://www.haomeiwen.com/subject/ftmvahtx.html