设置小提琴图的x轴位置。

huangapple go评论77阅读模式
英文:

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))

设置小提琴图的x轴位置。<!-- -->


vioplot(toPlot$value~toPlot$variable, 
        at = c(1,2,4,5,8), 
        ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))

设置小提琴图的x轴位置。<!-- -->

<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(&quot;vioplot&quot;)
library(vioplot)
#&gt; Loading required package: sm
#&gt; Package &#39;sm&#39;, version 2.2-5.7: type help(sm) for summary information
#&gt; Loading required package: zoo
#&gt; 
#&gt; Attaching package: &#39;zoo&#39;
#&gt; The following objects are masked from &#39;package:base&#39;:
#&gt; 
#&gt;     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))

设置小提琴图的x轴位置。<!-- -->


vioplot(toPlot$value~toPlot$variable, 
        at = c(1,2,4,5,8), 
        ylim=c(min(toPlot$value)-1, max(toPlot$value)+1))

设置小提琴图的x轴位置。<!-- -->

<sup>Created on 2023-07-18 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年7月18日 10:19:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定