Reputation: 21690
I've got 8 data vectors (MAP scores) of different length (different amount of documents rated), from 80 to 500. How do I read them to R and plot them to the same length in ggplot2? Consider them a different amount of datapoints ranging from 0 to 1. They should be scaled down/up so they fit into the same graph. And add a smoother to the picture. The scores range from 0 to 1. As example, I've got the vectors
vec1 = [1,0.8,0.6,0.8,0.6,0.6] # => +
vec2 = [1,0.8,0.6,0.4] # => *
and the plot should look like:
+
+* +
+ *+ +
*
but with lines.
Upvotes: 2
Views: 2534
Reputation: 179408
Here you go.
dat <- list(
vec1 = c(1,0.8,0.6,0.8,0.6,0.6), # => +
vec2 = c(1,0.8,0.6,0.4) # => *)
)
addX01 <- function(x, label="A"){
n <- length(x) - 1
data.frame(x=seq(0, 1, by=(1/n)), y=x, label=label)
}
raggedListToDf <- function(x, labels=LETTERS[seq_along(x)]){
do.call(rbind, lapply(seq_along(x), function(i) addX01(x[[i]], label=labels[i])))
}
plotData <- raggedListToDf(dat, labels=c("*", "+"))
ggplot(plotData, aes(x, y, label=label, group=label)) + geom_text()
Upvotes: 8