Reputation: 2886
I have a survey where each line represents a person and each column represents how long they took to complete the survey
I would like to plot a dot per timing per person so that if for example a person they completed the first part x1
in 10 minutes and the second part x2
in 12 minutes, the third part in 15 minutes x3
and the fourth part in 45 minutes x4
for ID 1 they would have these 4 dots on the y axis where the ID is the X Axis point
id <- sample(1:12)
x1 <- sample(1:250, 12, replace=F)
x2 <- sample(1:250, 12, replace=F)
x3 <- sample(1:250, 12, replace=F)
x4 <- sample(1:250, 12, replace=F)
mydf <- data.frame(id,x1,x2,x3,x4)
I tried using ggplot where i specified the x axis as the ID but im not sure how to represent all the other columns as different counts
Does anyone know if this is possible
Any help would be great
Upvotes: 2
Views: 521
Reputation: 24198
I believe we need to melt
your data.frame
first and then construct your desired plot.
library(reshape2)
melted <- melt(mydf, id.vars = "id") # Melt data
# Generate plot
library(ggplot2)
ggplot(melted, aes(factor(id), value, colour = variable)) +
geom_point()
Upvotes: 3