Is it possible to control the order of appearance of boxplot items in R language?
For example,
boxplot (iris[, 1:4])
Order Sepal.Length
, Sepal.Width
, Petal.Length
, Petal.Width
as shown in .
What should I do if I want to change it?
In this example, the data itself happens to be in alphabetical order.
If the original data is not, if you do not specify anything, it will automatically be ordered alphabetically.
It seems that the specification will end up.
Is it possible to put two Petal
to the left in this example?
How about changing the order of data columns?
boxplot(iris[,c(3,4,1,2)])
In R3.0.2
(OSX), I was able to display the Petal system on the left.
Additional:Supplement that there are many actual column names.
c(3,4,1,2)
above is a vector that specifies the column order of the original data, so if there is a rule in the column name, you can calculate the column order as a vector in advance and pass it from the outside.
For example, if you define a function such as mysort
that accepts column names as arguments and returns column order according to certain rules,
col.order<-mysort(colnames(iris))
boxplot(iris[,col.order])
can be
Alternatively, you can manage column names and order of appearance in csv, read them as data.frame
, and then generate them in column order.(Personally, hash library is recommended for computational quantities.)
© 2024 OneMinuteCode. All rights reserved.