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?
            Asked
            
        
        
            Active
            
        
            Viewed 713 times
        
    -1
            
            
        - 
                    *How* do you want to plot them? As boxplots? – Konrad Rudolph Mar 26 '15 at 12:43
- 
                    Provide a small reproducible example of your data. Are those vectors numeric? – talat Mar 26 '15 at 12:43
- 
                    Those vectors have timestamp values. These timestamps are the outliers of the data. Ex: timeinstancelist<-list(varname1=c(1,2,5,9,12), varname2=c(1,5,9,18,20), varname3=c(2,6,10), varname4=c(8)). Assume 1,2,5....as the timestamp values and there are approximately 80 such variables. – tushaR Mar 26 '15 at 12:47
- 
                    Have a look at https://stackoverflow.com/questions/5963269/ to find out how you can provide a reproducible example. – talat Mar 26 '15 at 12:50
- 
                    @KonradRudolph No, I just want to plot the timestamps on the y-axis as point type plots. – tushaR Mar 26 '15 at 12:53
1 Answers
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()

 
    
    
        JasonAizkalns
        
- 20,243
- 8
- 57
- 116
