title: R: Plotting a Graph with NA's
body: <p>I am working with the R programming language.</p>
  <p>I have the following data that contains 10 measurements for a set of people (and includes NA's):</p>
  <pre><code>my_data &lt;- structure(list(id = 1:20, weight_time_1 = c(NA, NA, NA, NA, 99.4800556826432, 
  NA, NA, NA, NA, 92.7723003148797, NA, 102.130637355002, NA, NA, 
  96.4306038435274, 117.519167258681, NA, NA, NA, NA), weight_time_2 = c(NA, 
  NA, NA, 100.096037354425, 98.5573457978251, NA, 99.2565971422039, 
  NA, NA, 78.2178327860056, NA, 93.1290042175411, NA, 105.999332486733, 
  102.324404273109, 106.249390147503, NA, NA, NA, NA), weight_time_3 = c(NA, 
  NA, NA, 109.653641754063, 108.67612106402, 89.245436013972, 76.0388764710753, 
  NA, 121.434141230992, 93.5040344542738, NA, 106.261290772666, 
  NA, 107.27650959864, 99.9614325607138, 106.822602397336, NA, 
  NA, NA, NA), weight_time_4 = c(NA, NA, NA, 83.4057073444694, 
  100.0475658129, 101.181524203485, 109.854456857605, NA, 109.39925298469, 
  100.127289780991, NA, 92.3537705948637, NA, 97.484431731186, 
  93.1880798156964, 98.2949614096827, NA, NA, NA, NA), weight_time_5 = c(85.9705471396862, 
  NA, 101.810197281424, 125.878759238011, 90.5377892614597, 100.977860860978, 
  105.206211167738, 105.925495763829, 95.0038093722839, 91.7697262180746, 
  112.751436397665, 89.3570085447357, NA, 105.334871042565, 107.101908594036, 
  121.466895783898, NA, NA, NA, NA), weight_time_6 = c(91.3939219450539, 
  NA, 102.295063295212, 112.648885364836, 92.858993235862, 84.9768973349691, 
  106.268407819189, 91.2142736262532, 94.5206092516322, 106.102317632812, 
  106.800383289515, 96.8243417950671, 112.526148273022, 96.0060934996047, 
  108.127666530717, 100.80395850135, NA, NA, NA, 97.1665601525516
  ), weight_time_7 = c(78.1538622765699, NA, 98.3267913598314, 
  97.694334342899, 88.2573884491152, 94.0391463446378, 79.107127345042, 
  98.6717305266368, 87.4584802875, 91.0212929680695, 115.449312672637, 
  108.505222479846, 87.7272780928247, 98.2950591116351, 108.64305435295, 
  100.971252881422, NA, NA, NA, 89.7627845887151), weight_time_8 = c(88.9847618154833, 
  NA, 75.9578295182105, 123.066624773516, 103.899907028919, 86.3922722708996, 
  101.056470605625, 93.9274704914096, 116.225266396545, 119.261812971557, 
  120.470004522712, 95.1540411812936, 103.625912955529, 119.112226243372, 
  97.2548085647629, 93.4809837458108, NA, 107.551887082473, 103.626395948971, 
  92.497583506856), weight_time_9 = c(106.965867937613, NA, 111.885847224286, 
  95.4347167550049, 89.629232996398, 99.279432759281, 111.111236025807, 
  106.187409603617, 95.0731389891664, 102.40946902701, 98.7215766413794, 
  108.440350789909, 111.841323303161, 98.6631240530225, 108.178201457868, 
  102.289607726024, 108.679229829576, 93.9424920702776, 102.660681952024, 
  90.7932196785015), weight_time_10 = c(98.5452360068031, 100.417384196154, 
  94.4492002344181, 100.711643341273, 119.565187908911, 103.54455492062, 
  74.0330331656656, 103.431332886172, 112.355083085616, 100.345180859457, 
  97.3988962137931, 96.9401740645521, 116.008033135044, 106.302406861972, 
  96.7028852299552, 111.699115637383, 95.3519501717543, 89.9061904342833, 
  107.36861168758, 102.797106848808)), row.names = c(NA, 20L), class = &quot;data.frame&quot;)
  </code></pre>
  <p>I would like to make a &quot;longitudinal&quot; graph for this data. I tried to do this two different ways:</p>
  <p><strong>Option 1:</strong> <a href="https://cran.r-project.org/web/packages/lcsm/vignettes/v0-longitudinal-plots.html" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/lcsm/vignettes/v0-longitudinal-plots.html</a></p>
  <pre><code>library(lcsm)
  library(ggplot2)
  library(tidyr)
  library(dplyr)
  library(stringr)
  
  x_var_list &lt;- c(&quot;weight_time_1&quot;, &quot;weight_time_2&quot;, &quot;weight_time_3&quot;, &quot;weight_time_4&quot;, &quot;weight_time_5&quot;, &quot;weight_time_6&quot;, &quot;weight_time_7&quot;, &quot;weight_time_8&quot;, &quot;weight_time_9&quot;, &quot;weight_time_10&quot;)
  
  plot_trajectories(data = my_data,
                    id_var = &quot;id&quot;, 
                    var_list = x_var_list,
                    xlab = &quot;Time&quot;, ylab = &quot;Value&quot;,
                    connect_missing = FALSE, 
                    random_sample_frac = 1, 
                    title_n = TRUE)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/HZDbz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HZDbz.png" alt="enter image description here" /></a></p>
  <p>This seemed to have worked, but produces a warning message stating that NA's were not plotted:</p>
  <pre><code>Warning messages:
  1: Removed 64 row(s) containing missing values (geom_path). 
  2: Removed 64 rows containing missing values (geom_point). 
  </code></pre>
  <p><strong>Option 2:</strong> <a href="https://www.r-bloggers.com/2015/08/managing-longitudinal-data-conversion-between-the-wide-and-the-long/#google_vignette" rel="nofollow noreferrer">https://www.r-bloggers.com/2015/08/managing-longitudinal-data-conversion-between-the-wide-and-the-long/#google_vignette</a></p>
  <pre><code>dat &lt;- reshape(my_data, varying= c(&quot;weight_time_1&quot;, &quot;weight_time_2&quot;, &quot;weight_time_3&quot;, &quot;weight_time_4&quot;, &quot;weight_time_5&quot;, &quot;weight_time_6&quot;, &quot;weight_time_7&quot;, &quot;weight_time_8&quot;, &quot;weight_time_9&quot;, &quot;weight_time_10&quot;), idvar=&quot;id&quot;, direction=&quot;long&quot;)
  
  
  library(ggplot2)
  ggplot(dat, aes(x=time, y=measure, colour=tx, group=id)), geom_line(alpha=.5)
  </code></pre>
  <p>But this returns the following error: Error in guess(varying) :</p>
  <pre><code>failed to guess time-varying variables from their names
  </code></pre>
  <p><strong>Can someone please show me how to fix this and plot this data? I would like the NA's to appear on the graph.</strong></p>
  <p>Thanks!</p>