I have a matrix of 6 columns and 5 rows. The first column is week index and rest are percentage changes. It may look like this:
I want to create a aesthetically pleasing line graphs in R using either ggplot or dygraph with labelled axis and colored lines (for 2nd to 6th column)
Any extended help would be appreciated.
Your request of an "aesthetically pleasing" graph is a little vague, but here is how you could produce a labelled and colourful plot using ggplot2.
First simulate some data to fit the format you describe:
To produce the desired plot with ggplot2, you should convert the data to a "long" format. I use the function
gatherfrom the packagetidyr(you could also use the equivalentmeltfunction from packagereshape2).Now you can easily produce a plot by colouring using the
pct_typevariable.Note: In case the variable
weekis a factor (I assumed it was a number, as you referred to it as "week index"), you would also need to tellggplotto group data bypct_type, like so: