Stack Area Chart creating Holes/Gaps

ggplot2

#1

Hi,

I am currently trying to create a Stacked Area Chart. The Problem is, that it creates gaps on several positions. i already red in other threads, that this happen, if the different categories of the data doesnt start on the same time step and you can add 0 to prevent this, but my Data is complete. The problem seems to be the interpolation of the data. Here is the Code:

p=ggplot(Df_plot, aes(x=Time, y=Values, fill=Tech)) +
geom_area()

it creates:

Here is an example of the Data:

"Time" "Tech" "Values"
"1" 0 "a" 0
"2" 1 "a" -83.6519
"3" 2 "a" -0.9106
"4" 3 "a" 0
"5" 4 "a" 0
"6" 5 "a" 0
"7" 6 "a" 5.4218
"8" 7 "a" 60.311
"9" 8 "a" 68.8022
"10" 9 "a" 69.2066
"11" 10 "a" 65.0609
"12" 11 "a" 59.8645
"13" 12 "a" 42.2422
"14" 13 "a" 0
"15" 14 "a" 0
"16" 15 "a" 0
"17" 16 "a" 0
"18" 17 "a" 0
"19" 18 "a" 0
"20" 19 "a" 0
"21" 20 "a" 0
"22" 21 "a" 0

Hope someone can help!


#2

If you think about it, area is continuous, and your data is discrete -- not every event happens every day. I think you'll do better with geom_col

(which is all I could do with the sample data).

ggplot(data = series, aes(x=Time, y = Values)) + geom_col()

#3

The problem you are seeing is due to having a mix of positive and negative values in some series. There is no real way to avoid the gaps as the areas switch back and forth from positive to negative. There is some more discussion of this on this ggplot2 issue. geom_col() might indeed be your best bet here.