I have a melted dataset:
ID variable mean sd sem
1 0001 1 0.000000000 0.000000000 0.000000000
2 0001 2 0.000000000 0.000000000 0.000000000
3 0001 3 1.374013050 0.083787761 0.001524927
4 0001 4 1.622939744 0.232510250 0.004231658
5 0001 5 0.004092427 0.004076841 0.000074198
There are 120 variables for each of 50 unique IDs.
[Edited based on comments]
I would like to create a single plot for each variable, showing the mean & sem for each ID. I would like the means to be ordered
First: I would like to create a plot for one variable:
ggplot(subset(dataset, variable=="1"), aes(x = ID, y = mean)) +
geom_bar(position = position_dodge(), stat = "identity") +
geom_errorbar(aes(ymin=mean-sem, ymax=mean+sem)) +
theme(axis.title.x = element_text(face="bold",size=16),
axis.text.x = element_text(angle=90, colour = "black", vjust=1, hjust = 1, size=14),
axis.text.y = element_text(colour = "black", size=14),
axis.title.y = element_text(face="bold", size=16),
plot.title = element_text(size = 18),
legend.title = element_text(size=14),
legend.text = element_text(size = 13),
legend.position="right",
strip.text.x = element_text(size=12, face="bold"),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(colour="black")) + ylab("Mean") + xlab("ID")
Now, I would like to do the same thing for all 120 variables. How do I initialize a for statement to create a plot for each variable?
I tried:
for(i in 1:120)
{unique <- unique(test$variable)
ggplot(unique[i], aes(x = KGID, y = mean))
But that doesn't work. I want ggplot() to take each unique ID and make the plot.