-1

I have data:

structure(list(Group.1 = structure(c(17897, 17928, 17956, 17987, 18017, 18048, 18078, 18109, 18140, 18170, 18201, 18231, 18262, 18293, 18322, 18353, 18383, 18414, 18444, 18475, 18506, 18536, 18567, 18597), class = "Date"), w_VidP = c(92.5925925925926, 95.0391644908616, 91.2820512820513, 94.1326530612245, 96.8838526912181, 93.6962750716332, 94.1340782122905, 95.1219512195122, 94.6635730858469, 91.0869565217391, 93.9130434782609, 95.0664136622391, 93.7833037300178, 93.7943262411348, 73.7814554522784, 78.7838462772634, 80.9031501001477, 81.311686371836, 83.6755826502932, 85.4640458697901, 92.2114249211173, 93.379673311808, 93.451937568209, 92.7840865787669), h_VidP = c(90.9090909090909, 83.3333333333333, 88.2352941176471, 92.8571428571429, 90.4761904761905, 0, 0, 0, 0, 96, 0, 0, 0, 96, 78.3102143757881, 85.030303030303, 87.3960332693538, 87.9140328697851, 89.0800794176042, 90.1778808971384, 94.3351505095994, 94.8272066916135, 94.7485536270583, 93.8617401668653 ), nwo_VidP = c(84.6153846153846, 85.7142857142857, 85.7142857142857, NaN, NaN, 90.9090909090909, NaN, 87.5, 94.7368421052632, 90.9090909090909, 89.6551724137931, 66.6666666666667, 80, 61.5384615384615, 72.1188118811881, 81.7953861584754, 84.7028086218158, 84.8016997167139, 85.1056211958468, 86.2537123462028, 91.467481934408, 92.6741803278689, 92.8238838674336, 92.0883387938357)), row.names = c(NA, -24L), class = "data.frame")

This data looks like:

      Group.1   w_VidP   h_VidP nwo_VidP
1  2019-01-01 92.59259 90.90909 84.61538
2  2019-02-01 95.03916 83.33333 85.71429
3  2019-03-01 91.28205 88.23529 85.71429
4  2019-04-01 94.13265 92.85714      NaN
5  2019-05-01 96.88385 90.47619      NaN
6  2019-06-01 93.69628  0.00000 90.90909
7  2019-07-01 94.13408  0.00000      NaN
8  2019-08-01 95.12195  0.00000 87.50000
9  2019-09-01 94.66357  0.00000 94.73684
10 2019-10-01 91.08696 96.00000 90.90909
11 2019-11-01 93.91304  0.00000 89.65517
12 2019-12-01 95.06641  0.00000 66.66667
13 2020-01-01 93.78330  0.00000 80.00000
14 2020-02-01 93.79433 96.00000 61.53846
15 2020-03-01 73.78146 78.31021 72.11881
16 2020-04-01 78.78385 85.03030 81.79539
17 2020-05-01 80.90315 87.39603 84.70281
18 2020-06-01 81.31169 87.91403 84.80170
19 2020-07-01 83.67558 89.08008 85.10562
20 2020-08-01 85.46405 90.17788 86.25371
21 2020-09-01 92.21142 94.33515 91.46748
22 2020-10-01 93.37967 94.82721 92.67418
23 2020-11-01 93.45194 94.74855 92.82388
24 2020-12-01 92.78409 93.86174 92.08834

I would like to graph the w_VidP, h_VidP, nwo_VidP, on a single graph with a y-axis titled "% Vid". If anyone has a good idea to calculate a p-value to see if these three groups differ across time, that would be great? Graph would look like: https://i.stack.imgur.com/HfOCA.jpg. Ignore the two y-axes. I just need one. I would like the three different groups to have three differently colored lines.

Evan
  • 1,477
  • 1
  • 17
  • 34
  • I can't see the graph but I think this has been covered extensively here previously. See https://stackoverflow.com/questions/10730303/how-to-plot-multiple-lines-in-r or https://stackoverflow.com/questions/14860078/plot-multiple-lines-data-series-each-with-unique-color-in-r or https://stackoverflow.com/questions/17150183/plot-multiple-lines-in-one-graph or https://stackoverflow.com/questions/3777174/plotting-two-variables-as-lines-using-ggplot2-on-the-same-graph or https://stackoverflow.com/questions/7912180/plotting-multiple-lines-from-a-data-frame-in-r – thelatemail May 11 '21 at 22:57
  • You can click on the link here: https://imgur.com/a/yJ1WZkr or here: https://imgur.com/a/yJ1WZkr or https://imgur.com/a/yJ1WZkr or https://imgur.com/a/yJ1WZkr or https://imgur.com/a/yJ1WZkr or https://imgur.com/a/yJ1WZkr... Thanks so much for the help! – Evan May 11 '21 at 23:24
  • I can't see it because imgur is blocked from this computer, but thank you for the snarky reply. – thelatemail May 11 '21 at 23:25

1 Answers1

0

I believe you're looking for something like the code below (note: I named the dataframe "df"). Please let me know if this helps!

colors <- c("h_VidP" = "blue", "w_VidP" = "red", "nwo_VidP" = "green")

df %>%
  ggplot(aes(Group.1)) + geom_line(aes(y = w_VidP, color = "w_VidP")) +
geom_line(aes(y = h_VidP, color = "h_VidP")) +
geom_line(aes(y = nwo_VidP, color = "nwo_VidP")) +
labs(title = "Title", x = "Dates", y = "% Vid", color = "Legend") +
theme(legend.position = "right") +
scale_fill_discrete(name = "Vids", labels = c("w_VidP", "h_VidP", "nwo_VidP")) +
theme(plot.title = element_text(hjust = 0.5))
DJS
  • 73
  • 6