0

I'm trying to read a CSV:

5.0;72.0;
6.0;72.0;
4.0;72.0;
5.0;72.0;
4.0;72.0;

...and have one ggplot2 with two functions: first column and second column, both colored differently.

What I've tried so far:

>dt <- fread('C:\\Users\\csvFile.txt')  
>print(dt)
    V1 V2 V3
 1:  5 72 NA
 2:  6 72 NA
 3:  4 72 NA
 4:  5 72 NA
 5:  4 72 NA

...and now I'm stuck. How do I plot both V1 and V2 in the same plot?

I know how to make the plot colored and continuous, but I have no idea how to actually plot the values:

>ggplot(dt, aes(x=x, y=y)) + geom_line() +geom_area(fill="blue")

My desired chart would look something like this (except that i have no X-axis ("density") as my values are a simple timeseries):

enter image description here

1 Answer 1

1

I would do something like this...

library(tidyr) #for the gather
df$time = seq_along(df$V1) #add your time variable
df2 <- df %>% gather(key=type,value=value,-time) #convert to long format
ggplot(df2,aes(x=time,y=value,fill=type))+
          geom_area(alpha=0.2,position="identity")
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.