chiffa
chiffa

Reputation: 2088

R beeswarm plot by grouping by rows?

I am using R beeswarm library to plot my data.

When I am plotting my dataframe directly, it does nice plot by processing columns as separate classes and plotting them accordingly.

However, when I try to plot a transpose of the same dataframe, for some reason it flattens my dataframe before plotting it and plots all the classes aggregated.

Is this a normal behavior or a bug?

Is there a way to force beeswarm to use rows and not columns as the classes to group on?

Edit: data is a 94 x 40 data frame with pretty much random numbers here are the commands:

beeswarm(mydata, cex=0.4)

beeswarm(t(mydata), cex=0.4)

and the resulting plots: column-wise row-wise

Upvotes: 0

Views: 891

Answers (1)

Ruthger Righart
Ruthger Righart

Reputation: 4921

Probably this problem is due to your transposed data being of class matrix

Example data

dd<-data.frame(a=c(1,2,3,3,4,4,4,5,5,5,5,6,6,7,9), b=c(3,3,4,4,4,5,5,5,5,5,6,6,6,7,9), c=c(5,5,5,6,6,6,7,7,7,7,8,9,11,11,12))

This gives a nice plot for each column

beeswarm(dd, pch = 16, col = rainbow(8))

Now the data are transposed and of class matrix. A beeswarm will take all columns altogether as if it were one column

ndd<-t(dd)

beeswarm(ndd, pch = 16, col = rainbow(8))

But if the transposed data are converted to data.frame, this will display all columns separately:

df<-data.frame(t(dd))
colnames(df)<-c(letters[1:15])
beeswarm(df, pch = 16, col = rainbow(8))

enter image description here

Upvotes: 1

Related Questions