Reputation: 1268
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):
Upvotes: 0
Views: 87
Reputation: 18425
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")
Upvotes: 1