私は次のようなデータセットを持っています:
xStart xEnd yStart yEnd
a 100 200 70 90
b 40 120 60 200
「a」と「b」でグループ化された時間グラフをプロットし、イベントが「a」の場合は100で始まり200で終わり、他のイベントが「a」の場合は70で始まり90で終わることを示す必要があります。gnuplotまたはRでこれを行うにはどうすればよいですか?
# I'm using the example data you gave.
# but you'd be reading in a csv file or something similar.
df <- read.table(textConnection(" xStart xEnd yStart yEnd
a 100 200 70 90
b 40 120 60 200"), header = T)
# add the row names as a column
df$cols <- rownames(df)
> df
xStart xEnd yStart yEnd cols
a 100 200 70 90 a
b 40 120 60 200 b
library(plyr)
# instead of gnuplot (which I don't use), I'm using ggplot2
# see http://had.co.nz for more info about the package.
# below, the function ddply (in plyr) splits the data by cols (a or b)
# then plots those data and returns it to a list named plots.
# the length of plots will be equal to the number of unique groups in your data
library(ggplot2)
# change the plot type below to whatever you like.
plots <- dlply(df, .(cols), function(x){
data <- data.frame(x1 = as.numeric(x[, 1:2]), y1 = as.numeric(x[, 3:4]))
ggplot(data, aes(x1, y1)) + geom_point() + ggtitle(unique(x$cols))
})
plots[1]
# to see the first plot
plots[2]
# to see the second one
length(plots) # to see how many plots were generated