如何为数值制作漂亮有序的构面标签?

Eti*_*rie 2 r ggplot2 facets

我经常根据数字变量进行调查,但我希望facet标签比简单数字更具解释性.我通常创建一个新的标签变量,其数字值粘贴到解释性文本.但是,当值在小数点前有多个位置时,第一个数字用于对因子进行排序.有什么建议可以避免吗?

iris[,1:4]<-iris[,1:4]*10
Run Code Online (Sandbox Code Playgroud)

当它在小数点之前没有多于一个值时,这对虹膜可以正常工作.

iris$Petal.Width.label<-paste("Petal.Width=", iris$Petal.Width)



iris$Petal.Width.label<-paste("Petal.Width=", iris$Petal.Width)


qplot(data=iris,
      x=Sepal.Length,
      y=Sepal.Width,
      colour=Species)+facet_wrap(~Petal.Width.label)
Run Code Online (Sandbox Code Playgroud)

绘制错过有序的方面

相关:
ggplot:如何更改构面标签?
如何更改ggplot中的构面标签的顺序(自定义构面包装标签)

EDi*_*EDi 5

只需重新标记您的标签级别:

data(iris)
iris[ , 1:4] <- iris[ , 1:4] * 10
iris$Petal.Width.label <- paste("Petal.Width=", iris$Petal.Width)
# reoder levels by Petal.Width
iris$Petal.Width.label2 <- factor(iris$Petal.Width.label, 
                                  levels = unique(iris$Petal.Width.label[order(iris$Petal.Width)]))
qplot(data = iris,
      x = Sepal.Length,
      y = Sepal.Width,
      colour = Species)+
        facet_wrap( ~Petal.Width.label2)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述