I have a below data set.
TimeStamp data_1 data_2 data_3
15:11:37.474 99.791028 0.312498 99.47853
15:16:22.373 99.791028 0.729162 99.061866
15:21:37.424 99.791028 0.104166 99.686862
15:31:52.475 88.02027 90.520254
15:42:07.157 99.99936 0.208332 99.791028
15:43:22.279 99.99936 0.52083 99.47853
15:45:37.673 99.686862 0 99.686862
15:52:52.872 99.686862 0.729162 98.9577
I require to draw simple line graphs as below.But, all should be sharing same X and Y axis. For timestamp, sampling with 5 minutes is fine.
data_1 vs TimeStamp
data_2 vs TimeStamp
data_3 vs TimeStamp
What I have tried so far is as below.
df <- read.csv(file="c:\\td.csv")
df1 <- round(df[-1], 1)
ggplot(df, aes(df$id, rdat$f1)) + geom_point()
I know this is not the right approach and any help is appreciated.
It seems that you want something like the following. You want to convert your data in a wide format to a long format. I used melt()
, but you can use gather()
in the tidyr package too. From there, you just create a graphic. I do not know what you meant by saying "For timestamp, sampling with 5 minutes is fine." If you need further data manipulation, this will help you proceed further.
library(reshape2)
library(ggplot2)
temp <- melt(mydf, id.vars = "TimeStamp", variable.name = "data")
ggplot(data = temp, aes(x = TimeStamp, y = value, color = data,
group = data)) +
geom_line() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
DATA
mydf <- structure(list(TimeStamp = structure(1:8, .Label = c("15:11:37.474",
"15:16:22.373", "15:21:37.424", "15:31:52.475", "15:42:07.157",
"15:43:22.279", "15:45:37.673", "15:52:52.872"), class = "factor"),
data_1 = c(99.791028, 99.791028, 99.791028, 88.02027, 99.99936,
99.99936, 99.686862, 99.686862), data_2 = c(0.312498, 0.729162,
0.104166, NA, 0.208332, 0.52083, 0, 0.729162), data_3 = c(99.47853,
99.061866, 99.686862, 90.520254, 99.791028, 99.47853, 99.686862,
98.9577)), .Names = c("TimeStamp", "data_1", "data_2", "data_3"
), class = "data.frame", row.names = c(NA, -8L))
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.