I have a piece of data which is a dictionary of key value pairs, in this form:
"1.354395": [
87.4006653,
92.0,
84.0,
2.18594456,
6.58963251,
1.97522652,
33.8585548,
2.89522839,
0.0,
0.3756774
],
"1.355575": [
84.21513,
97.0,
94.0,
2.63353539,
9.701308,
1.48480618,
24.1026344,
5.00067139,
0.0,
0.476816237
],...
Here's how the data is in R:
list(`1.454552` = c(93.15171, 88, 91, 5.66755724, 6.469661, 2.06840134,
40.66451, 2.44088984, 0, 0.401849449), `1.455795` = c(87.7752151,
92, 87, 4.76685572, 2.86901379, 2.00754881, 8.92096, 4.836194,
0, 0.0966028), `1.455984` = c(81.08724, 97, 94, 2.54499722, 6.61629057,
2.2256844, 53.1162224, 2.008997, 0, 0.8071972), `1.456137` = c(85.67516,
81, 97, 8.783263, 7.65513325, 1.53414989, 41.64623, 2.329053,
0, 0.7988913), `1.456295` = c(88.17177, 94, 97, 6.011479, 7.758415,
2.070262, 29.4543114, 4.043613, 0, 0.4748996), `1.456457` = c(87.75609,
87, 89, 5.89587069, 9.498943, 1.66703343, 55.62601, 2.277172,
0, 0.358969629), `1.456705` = c(99.99199, 96, 90, 5.10459852,
9.459774, 1.52685452, 21.1448555, 5.652314, 0, 0.6192784), `1.456985` = c(96.77855,
86, 80, 9.057593, 7.29362965, 1.44890714, 16.3208141, 5.47197628,
0, 0.808024764)
The key is the time at which that list of values was added to the dictionary, and as such should be on the x axis, I then want to plot the each value in the list along the y axis with each value in the list being its own line graph. I have the data loaded into R but I'm quite new to R as a whole and I'm not too sure how to use plot()
over a series of values.
You can use ggplot()
for this. I hope I understood it correctly:
library(tidyverse)
data <- list(`1.454552` = c(93.15171, 88, 91, 5.66755724, 6.469661, 2.06840134,
40.66451, 2.44088984, 0, 0.401849449), `1.455795` = c(87.7752151,
92, 87, 4.76685572, 2.86901379, 2.00754881, 8.92096, 4.836194,
0, 0.0966028), `1.455984` = c(81.08724, 97, 94, 2.54499722, 6.61629057,
2.2256844, 53.1162224, 2.008997, 0, 0.8071972), `1.456137` = c(85.67516,
81, 97, 8.783263, 7.65513325, 1.53414989, 41.64623, 2.329053,
0, 0.7988913), `1.456295` = c(88.17177, 94, 97, 6.011479, 7.758415,
2.070262, 29.4543114, 4.043613, 0, 0.4748996), `1.456457` = c(87.75609,
87, 89, 5.89587069, 9.498943, 1.66703343, 55.62601, 2.277172,
0, 0.358969629), `1.456705` = c(99.99199, 96, 90, 5.10459852,
9.459774, 1.52685452, 21.1448555, 5.652314, 0, 0.6192784), `1.456985` = c(96.77855,
86, 80, 9.057593, 7.29362965, 1.44890714, 16.3208141, 5.47197628,
0, 0.808024764))
data <- bind_rows(data) %>% mutate(group= row_number()) %>%
pivot_longer(cols = -group, names_to = "time")
ggplot(data, aes(x = time, y=value, group=group)) +
geom_line(aes(col=as.factor(group)))
Created on 2020-04-26 by the reprex package (v0.3.0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.