Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

graph - Plotting multiple lines from a data frame in R

I am building an R function to plot a few lines from a data table, I don't understand why this is not working?

data = read.table(path, header=TRUE);
plot(data$noop);
lines(data$noop, col="blue");
lines(data$plus, col="green");

I am reading the data from a file I has which is formatted like this:

 noop         plus         mins
 33.3         33.3         33.3
 30.0         40.0         30.0
 25.0         50.0         25.0

This is the minimal representation of the dataset, which contains more headers and more data points. So each of the rows of this data set reflects a sample taken at a given time. So my objective is to read this data in from the file, and then plot each column as a series of points connected by lines of different color.

The approach I am using currently is only plotting 1 line, and not multiple lines.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have a look at the ggplot2 package

library(ggplot2)
library(reshape)
data <- data.frame(time = seq(0, 23), noob = rnorm(24), plus = runif(24), extra = rpois(24, lambda = 1))
Molten <- melt(data, id.vars = "time")
ggplot(Molten, aes(x = time, y = value, colour = variable)) + geom_line()

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...