Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2-line plotting with TIME series and multi-spline
    primarykey
    data
    text
    <p>This question's theme is simple but drives me crazy: 1. how to use <code>melt()</code> 2. how to deal with multi-lines in single one image?</p> <p>Here is my raw data:</p> <pre><code>a 4.17125 41.33875 29.674375 8.551875 5.5 b 4.101875 29.49875 50.191875 13.780625 4.90375 c 3.1575 29.621875 78.411875 25.174375 7.8012 </code></pre> <p>Q1: I've learn from this post <a href="https://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2">Plotting two variables as lines using ggplot2 on the same graph</a> to know how to draw the multi-lines for multi-variables, just like this: <img src="https://i.stack.imgur.com/NNzFB.png" alt="enter image description here"></p> <p>The following codes can get the above plot. However, the x-axis is indeed time-series.</p> <pre><code>df &lt;- read.delim("~/Desktop/df.b", header=F) colnames(df)&lt;-c("sample",0,15,30,60,120) df2&lt;-melt(df,id="sample") ggplot(data = df2, aes(x=variable, y= value, group = sample, colour=sample)) + geom_line() + geom_point() </code></pre> <p>I wish it could treat <strong>0 15 30 60 120 as real number</strong> to show the time series, rather than name_characteristics. Even having tried this, I failed. </p> <pre><code>row.names(df)&lt;-df$sample df&lt;-df[,-1] df&lt;-as.matrix(df) df2 &lt;- data.frame(sample = factor(rep(row.names(df),each=5)), Time = factor(rep(c(0,15,30,60,120),3)),Values = c(df[1,],df[2,],df[3,])) ggplot(data = df2, aes(x=Time, y= Values, group = sample, colour=sample)) + geom_line() + geom_point() </code></pre> <p>Loooooooooking forward to your help. </p> <p>Q2: I've learnt that the following script can add the spline() function for single one line, what about I wish to apply spline() for <strong>all the three lines</strong> in single one image? </p> <pre><code>n &lt;-10 d &lt;- data.frame(x =1:n, y = rnorm(n)) ggplot(d,aes(x,y))+ geom_point()+geom_line(data=data.frame(spline(d, n=n*10))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload