user6921981 user6921981 - 1 month ago 7
R Question

How to divide or separate boxplots in R?

I have more than 100 boxplots in one graph, which is hard to read. I want to divide it into 3 to 5 graphs, so it will be easy for people to see each boxplot.

boxplot(Flanker$TrialSlide_RT ~ Flanker$Subject, main="Boxplot", ylab="Reaction time", xlab="Number of participants", ylim=c(0,1000), las=1)


enter image description here

Answer

If you subset your original dataframe then you can plot each of them separately.

Lets say you split it every 20th rows. You can plot it using:

boxplot(DF[1:20,1]~DF[1:20,2],main="Boxplot 1", ylab="Reaction time", 
xlab="Number of participants", ylim=c(0,1000), las=1)

Where your dataframe is "DF" and by using DF[1:20,1] you're subsetting the first 20th rows of your dataframe and selecting the first column to plot agains the second column of the first 20th rows (DF[1:20,2]).

Comments