-1

I have a list which has multiple vectors (total 80) of various lengths. On the x-axis I want the names of these vectors. On the y-axis I want to plot the values corresponding to each vector. How can I do it in R?

tushaR
  • 2,992
  • 1
  • 18
  • 31

1 Answers1

6

One way to do this is to reshape the data using reshape2::melt or some other method. Please try and make a reproducible example. I think this is the gist of what you are after:

set.seed(4)
mylist <- list(a = sample(1:50, 10, T),
               b = sample(25:40, 15, T),
               c = sample(51:75, 20, T))
mylist
# $a
# [1] 30  1 15 14 41 14 37 46 48  4
# 
# $b
# [1] 37 29 26 40 31 32 40 34 40 37 36 40 33 32 35
# 
# $c
# [1] 71 63 72 63 64 65 56 72 67 63 75 62 66 60 51 74 57 65 55 73

library(ggplot2)
library(reshape2)

df <- melt(mylist)
head(df)
#   value L1
# 1    30  a
# 2     1  a
# 3    15  a
# 4    14  a
# 5    41  a
# 6    14  a

ggplot(df, aes(x = factor(L1), y = value)) + geom_point()

Plot

JasonAizkalns
  • 19,278
  • 6
  • 52
  • 107