代码之家  ›  专栏  ›  技术社区  ›  Xia.Song

几何区域多重绘图错误

  •  1
  • Xia.Song  · 技术社区  · 6 年前
    library(ggplot2)
    library(reshape2)
    data1 <- seq(1, 300, 3)
    data2 <- seq(1, 100, 0.5)
    acf1 <- acf(data1, plot = F, lag.max = 25)
    acf2 <- acf(data2, plot = F, lag.max = 25)
    df<- data.frame(lag = acf1$lag,acf1=acf1$acf,acf2=acf2$acf)
    colnames(df)<-c("lag","data1","data2")
    data<-melt(df,id="lag")
    ggplot(data, aes(x=lag, y=value)) +
    geom_area(aes(colour = variable, fill= variable),position="dodge") 
    

    enter image description here

    我想同时显示 Acf 两种颜色的值,但我不明白为什么它只显示一种颜色。我如何解决这个问题?

    1 回复  |  直到 6 年前
        1
  •  1
  •   PKumar    6 年前

    它实际上在那里,但被 data2 阻止,使用阿尔法(透明度)看到它,我也改变了你的道奇选项有点像下面。

    ggplot(data, aes(x=lag, y=value)) +
      geom_area(aes(colour = variable, fill= variable),position = position_dodge(width = 0.5), alpha = 0.5)
    

    如果你开始改变 position_dodge alpha ,您将以更好的方式看到这些块。

    产量 :

    enter image description here