Search code examples
rggplot2geom-bar

geom_area multiple plot error


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

I want to display both of the Acf values by two different color, but I can't figure out why it only displays one color. How can I solve this problem?


Solution

  • Its actually there but hidden by the data2 block , use alpha(transparency) to see it, I have also changed your dodge option a bit like below.

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

    If you start changing the width of position_dodge and alpha , you will see the these blocks in much better way.

    Output:

    enter image description here