英文:
Set the x-axis positions of violin plots
问题
我正在尝试为数据的各个离散化级别创建小提琴图。这些级别之间存在非线性关系,因此我希望在图表上显示出这种关系(例如,级别2距离级别1相差1步,但级别3距离级别2相差2步)。我可以使用带有'at'的箱线图来实现这一点,以便以下代码中的箱线图在变量值处间隔:
toPlot = data.frame(value = rnorm(50), variable = rep(c(1,2,4,5,8), each=10))
boxplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
是否有等效的方法(或任何方式)可以使用小提琴图来实现这一点?
英文:
I'm trying to create violin plots for various levels of discretisation of data. The levels are non-linearly related to each other so I want to show that on the graph (e.g. level 2 is 1 step from level 1, but level 3 is two steps from level 2). I can do this with a boxplot using 'at', such that the boxes in the following code are spaced at the variable values:
toPlot = data.frame(value = rnorm(50), variable = rep(c(1,2,4,5,8), each=10))
boxplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
Is there an equivalent (or any way to do this) with a violin plot?
答案1
得分: 1
你可以以完全相同的方式使用vioplot包,例如。
# install.packages("vioplot")
library(vioplot)
#> Loading required package: sm
#> Package 'sm', version 2.2-5.7: type help(sm) for summary information
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
toPlot = data.frame(value = rnorm(50), variable = rep(c(1,2,4,5,8), each=10))
boxplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
<!-- -->
vioplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
<!-- -->
<sup>Created on 2023-07-18 with reprex v2.0.2</sup>
英文:
You can use the vioplot package in exactly the same way, e.g.
# install.packages("vioplot")
library(vioplot)
#> Loading required package: sm
#> Package 'sm', version 2.2-5.7: type help(sm) for summary information
#> Loading required package: zoo
#>
#> Attaching package: 'zoo'
#> The following objects are masked from 'package:base':
#>
#> as.Date, as.Date.numeric
toPlot = data.frame(value = rnorm(50), variable = rep(c(1,2,4,5,8), each=10))
boxplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
<!-- -->
vioplot(toPlot$value~toPlot$variable,
at = c(1,2,4,5,8),
ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))
<!-- -->
<sup>Created on 2023-07-18 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论