我经常根据数字变量进行调查,但我希望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)
只需重新标记您的标签级别:
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)