代码之家  ›  专栏  ›  技术社区  ›  user3579222

如何删除堆叠图中的水平空间

  •  0
  • user3579222  · 技术社区  · 7 年前

    期望输出: enter image description here

    enter image description here

    重新调整数字有帮助,但应该更宽。

    ggplot(melt(portfolios), aes(x=variable, y=value)) + 
      geom_area(aes(colour = portfolio, fill= portfolio), position = 'stack') +
      theme(axis.title.x=element_blank(),
            axis.text.x=element_blank(),
            axis.ticks.x=element_blank()) +
      geom_line(aes(y=0))
    
    Excerpt of the DataFrame (melt(portfolios)):
          portfolio variable value
       1:         1        1   123
       2:         2        1   131
       3:         3        1   116
       4:         4        1   142
       5:         5        1   141
      ---                         
    6996:         6      700   251
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Chase    7 年前

    你能用吗 geom_bar() 具有 width = 1

    library(ggplot2)
    
    portfolios <- data.frame(portfolio = rep(1:10, each = 100), variable = 1:100, value = runif(1000))
    
    ggplot(portfolios, aes(x=variable, y=value, fill = factor(portfolio))) +
      geom_bar(position = "stack", stat = "identity", width = 1) +
      #geom_area(aes(colour = portfolio, fill= portfolio), position = 'stack') +
      theme(axis.title.x=element_blank(),
            axis.text.x=element_blank(),
            axis.ticks.x=element_blank()) +
      geom_line(aes(y=0))
    

    产量:

    enter image description here