I have a dataframe in R. First column is date. The rest columns are data for each category.
Date View1 View2 View3 View4 View5 View6
1 2010-05-17 13 10 13 10 13 10
2 2010-05-18 11 11 13 10 13 10
3 2010-05-19 4 12 13 10 13 10
4 2010-05-20 2 10 13 10 13 10
5 2010-05-21 23 16 13 10 13 10
6 2010-05-22 26 15 13 10 13 10
How can plot a timeplot with two lines? Each line for each column. i.e one line for View1, one line for View2, one line for View3 and so on. The x-axis is Date. Is there a function in ggplot can achieve this easily?
I searched other posts, see a solution below, but it gives me nothing on the plot.
mydf %>% gather(key,value, View1, View2, View3, View4, View5, View6 ) %>% ggplot(aes(x=Date, y=value, colour=key))
I also tried the commands below.
test_data_long1 <- melt(mydf, id="Date")
ggplot(data=test_data_long1,
aes(x=date, y=value, colour=variable)) +
geom_line()
It gives me an error.
Don't know how to automatically pick scale for object of type function. Defaulting to continuous.
Error: All columns in a tibble must be 1d or 2d objects:
* Column `x` is function