Reputation: 1231
I have a quick question on data visualization. I need to create a stacked line chart with points (geom_point
) on the data point. I am able to create stacked chart with help of code below, but am having hard time figuring out how to add points to the data.
here are the content of test.csv:
Date Category Value
3/6/15 A 6.00
3/13/15 A 16.00
3/20/15 A 10.00
3/27/15 A 15.00
4/3/15 A 18.00
4/10/15 A 30.00
3/6/15 B 2
3/13/15 B 5.00
3/20/15 B 12.00
3/27/15 B 17.00
4/3/15 B 19.00
4/10/15 B 29.00
3/6/15 C 10
3/13/15 C 10
3/20/15 C 10
3/27/15 C 10
4/3/15 C 10
4/10/15 C 10
and here is my code:
df = read.csv("test.csv", header = T)
df$Date = as.Date(df$Date, format = "%m/%d/%y")
ggplot(df, aes(x = Date, y = Value, fill = Category)) + geom_area(colour="black", size=0.2, alpha=.4)
I tried adding geom_point()
, but it does this.
I want these points on the stacked plot. Any help will be appreciated!
Thanks!
Upvotes: 2
Views: 702
Reputation: 32436
Use position_stack
ggplot(df, aes(x = Date, y = Value, fill = Category)) +
geom_area(colour="black", size=0.2, alpha=.4) +
geom_point(position=position_stack())
Upvotes: 6