Domanda

I have been looking through the net but cant work out how to plot multiple boxplots grouped by two categories in R.

A sample of my dataset can be reproduced with the following:

mus <- read.table(text='PeakFreq AvgFreq Q1Freq DeltaFreq RMSAMP SEX 
2756.2    125.4   1378.1  12735.8 1014201.4   1 
2067.2    125.7   1378.1  13353.3 1072159.1   1 
2067.2    124.7   1378.1  14568.8 1005498.6   1 
2067.2    126.2   1378.1  13781.2 1137817.5   1 
2067.2    124.8   1378.1  12009.4 917528      1 
2067.2    125.1   1378.1  12009.4 962350.1    1 
2067.2    125.6   1378.1  12796.9 1035925.5   1 
1378.1    125.7   1378.1  14157.1 1106302.5   1 
1378.1    124.9   1378.1  14495.6 1035889.1   1 
2067.2    125.6   1378.1  13231.4 1066041.4   1 
2067.2    126.2   1378.1  12870.2 1107624     1 
2067.2    125.3   1378.1  12509   1006671.4   1 
2067.2    125.5   1378.1  13111   1058175.1   1 
2067.2    125.7   1378.1  15338.4 1165810.5   1 
2067.2    125.1   1378.1  14676.2 1055849     1 
2067.2    126     1378.1  12930.4 1089473.4   1 
2067.2    125.5   1378.1  12448.8 1030328.8   1 
2067.2    125.5   1378.1  12870.2 1025250     1 
2067.2    125.8   1378.1  12328.4 1036224.7   1 
2067.2    125.3   1378.1  12208   980925.3    1 
2067.2    125.5   1378.1  12749.8 1029305     1 
2067.2    126.3   1378.1  11846.8 1088899.2   1 
2756.2    122.2   2067.2  14760.4 760858.1    2 
2756.2    122.8   2067.2  16843.4 866102.3    2 
3445.3    124.1   2756.2  14676.2 946382.7    2 
2756.2    124     2067.2  14676.2 923365.4    2 
2756.2    121     2067.2  15218   674616.9    2 
2756.2    120.8   2067.2  14917   646319.4    2 
2756.2    122.4   2067.2  16060.8 804943.2    2 
2756.2    123.9   2756.2  15759.8 947163.7    2 
2756.2    123.8   2067.2  14315   882770      2', header=TRUE)

SEX is male and female (1, 2).

I need to divide the variables into male and female in the box plot, like this:

boxplot(AvgFreq ~ SEX, data=mus, notch =TRUE, xlab="Sex") 

But with multiple variables in the same graph. Any suggestions on how to do this would really be appreciated!

Rebecca

È stato utile?

Soluzione

Multiple variable in the same plot would cause a messy plot due to the different scales. I recommend to create multiple plots like this:

x<-NULL
for (i in 1:10)
  x<-cbind(x, runif(10000, 5, 10))

par(mfrow=c(2,5))
for (i in 1:10)
  hist(x[,i], xlab=i)
par(mfrow=c(1,1)) # don't forget to set back the layout
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top