need to create a stack bar chart

后端 未结 1 1269
刺人心
刺人心 2021-01-29 14:58

I have three columns with date, var1 and var2. I like to create bar chart date being the x axis and var1 and var2 is y axis. I can do this in line chart but I really like to see

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 15:07

    How about this, with ggplot2

    # load libraries
    library(ggplot2)
    library(reshape2)
    # load data
    df1 <- read.table(header=TRUE, text=
    "Date         var1     var2
    2011-12-06  37608.1    12304.2
    2011-12-07  76430.9    28617.7
    2011-12-08  93112.3    33414.6
    2011-12-09 100334.8    28112.0
    2011-12-10  70474.0    23641.4
    2011-12-11 231113.6    78172.5")
    # reshape for plotting
    df1.m <-melt(df1)
    # make a quick plot
    qplot(x = factor(Date), y = value, data = df1.m, geom = "bar", fill = variable)
    

    And the resulting plot...

    enter image description here

    0 讨论(0)
提交回复
热议问题