I love the JMP variability plot. (link) It is a powerful tool.
我喜欢JMP变异性图。(link)这是一个强大的工具。
The example the plot has 2 x-axis labels, one for part-number and one for operator.
这个例子有2个x轴标签,一个是部分数字,另一个是操作符。
Here the JMP variability plot displays more than 2 levels of variables. The following splits by oil amount, batch size, and popcorn type. It can take some work to find the right sequence to show strongest separation, but this is an excellent tool for communication of information.
这里的JMP变异性图显示了两个以上的变量级别。下面根据油量、批次大小和爆米花类型进行划分。找到合适的序列来显示最强烈的分离可能需要一些工作,但是这是一个很好的信息交流工具。
How does one do this, the multiple-level x-labels, with R using the ggplot2 library?
如何使用ggplot2库来实现这一点?
The best that I can find is this (link, link), which separates based on cylinder count, but does not make the x-axis labels.
我能找到的最好的是这个(link, link),它根据柱面数量分离,但不做x轴标签。
My example code is this:
我的示例代码是:
#reproducible
set.seed(2372064)
#data (I'm used to reading my own, not using built-in)
data(mtcars)
attach(mtcars)
#impose factors as factors
fact_idx <- c(2,8:11)
for(i in fact_idx){
mtcars[,i] <- as.factor(mtcars[,i])
}
#boxplot
p <- ggplot(mtcars, aes(gear, mpg, fill=cyl)) +
geom_boxplot(notch = TRUE)
p
The plot this gives is:
它给出的情节是:
How do I make the x-axis lables indicate both gears and cylinders?
如何使x轴标签同时显示齿轮和钢瓶?
在jmp中,我得到了这个:
1 个解决方案
#1
3
You could use R-package VCA which comes with function varPlot implementing variability charts similar to JMP. There are multiple examples provided in the help. Your example would look like this:
您可以使用R-package VCA,它带有函数varPlot实现可变性图,类似于JMP。在帮助中提供了多个示例。你的例子是这样的:
library(VCA)
dat <- mtcars[order(mtcars$cyl, mtcars$gear),]
# default
varPlot(mpg~cyl/gear, dat)
# nicely formatted
varPlot(mpg~cyl/gear, dat,
BG=list(var="gear", col=paste0("gray", c(90,80,70)),
col.table=T),
VLine=list(var="cyl"), Mean=NULL,
MeanLine=list(var=c("cyl", "gear"), col=c("blue", "orange"),
lwd=c(2,2)),
Points=list(pch=16, cex=1))
#1
3
You could use R-package VCA which comes with function varPlot implementing variability charts similar to JMP. There are multiple examples provided in the help. Your example would look like this:
您可以使用R-package VCA,它带有函数varPlot实现可变性图,类似于JMP。在帮助中提供了多个示例。你的例子是这样的:
library(VCA)
dat <- mtcars[order(mtcars$cyl, mtcars$gear),]
# default
varPlot(mpg~cyl/gear, dat)
# nicely formatted
varPlot(mpg~cyl/gear, dat,
BG=list(var="gear", col=paste0("gray", c(90,80,70)),
col.table=T),
VLine=list(var="cyl"), Mean=NULL,
MeanLine=list(var=c("cyl", "gear"), col=c("blue", "orange"),
lwd=c(2,2)),
Points=list(pch=16, cex=1))