سؤال

It's not my data but we can use it as an example:

Name     1st   2nd   3rd   4th   5th  6th  7th   
Gregg     0    0.6   1     0.2   0    0.5    1  
Mike     0.4    1    0.6   0     0    0      0 
Susane    1     0    0     0     1    0.3    0 
Marcel    0     1    0.75  0.25  0    0      0 

I would like to get a line-plot of every row of this data. How can I do it efficiently for a big data set?

For every row, the maximum is always 1.

هل كانت مفيدة؟

المحلول

As you didn't mention what kind of plot you want, here are two examples (with the ggplot2 package):

# reading the data
df <- read.table(text = "Name     first   second   third   fourth   fifth  sixth  seventh   
Gregg     0    0.6   1     0.2   0    0.5    1  
Mike     0.4    1    0.6   0     0    0      0 
Susane    1     0    0     0     1    0.3    0 
Marcel    0     1    0.75  0.25  0    0      0", header = TRUE)

# transforming the data to long format
library(reshape2)
df2 <- melt(df, id = "Name")

# creating a barplot
require(ggplot2)
ggplot(df2, aes(x = Name, y = value, fill = variable)) +
  geom_bar(stat = "identity", position = "dodge")

enter image description here

# creating a line plot
ggplot(df2, aes(x = as.numeric(variable), y = value)) +
  geom_line() +
  facet_grid(~ Name)

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top