2

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)

enter image description here

I tried adding geom_point(), but it does this.

enter image description here

I want these points on the stacked plot. Any help will be appreciated!

Thanks!

1 Answer 1

6

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())

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.