Graphic vectors of different lengths with ggplot2

I have 8 data vectors (MAP estimates) of different lengths (different number of documents evaluated), from 80 to 500. How do I read them in R and draw them one length in ggplot2? Consider their different number of data points in the range from 0 to 1. They should be reduced / increased so that they fit into the same graph. And add a smoother image. Ratings range from 0 to 1. As an example, I have vectors

vec1 = [1,0.8,0.6,0.8,0.6,0.6] # => + vec2 = [1,0.8,0.6,0.4] # => * 

and the graph should look like this:

 + +* + + *+ + * 

but with lines.

+2
r ggplot2
source share
1 answer

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() 

enter image description here

+7
source share

All Articles