I want to make a plot that is similar to beanplot
or violin
plot, but instead of the symmetric shapes, i want to plot two different distributions on the different sides of the center line. Something like figure 4 in this article [pdf]http://www.jstatsoft.org/v28/c01/paper.
我想画一个类似于豆状图或小提琴图的图,但我不想画对称的形状,我想画两个不同的分布在中心线的不同边。类似于本文中的图4 [pdf]http://www.jstatsoft.org/v28/c01/paper。
I want to use the grid
graphics engine in R
. Any pointers will be useful. I looked at the lattice
package and the histogram
function in lattice
package, but that is not what i want to do.
我想在r中使用网格图形引擎,任何指针都是有用的。我看了晶格包和晶格包中的直方图函数,但这不是我想做的。
Any help/pointers are appreciated.
任何帮助/指针是感激。
1 个解决方案
#1
4
You can reasonably easily get the half-violin plot with fairly simple modifications to the function, panel.violin
in Sarkar's lattice package. There are four lines in that function that can be altered inside the grid.polygon
call to change from "two-sided" density plotting to single sided density plotting. First require(lattice)
and require(grid)
. Then type panel.violin
. I'll show you the "horizontal" alteration:
你可以很容易地得到半小提琴图与相当简单的修改功能,面板。萨卡尔晶格包中的小提琴。该函数中有四行可以在网格中修改。多边形要求从“双面”密度绘制变为单面密度绘制。首先需要(晶格)和要求(网格)。然后panel.violin类型。我将向你展示“水平”改变:
require(grid)
panel.violin2 <-
# snipped all the arguments and processing
grid.polygon(x = c(dx.list[[i]] ),
# Notice I removed: ... ,rev(dx.list[[i]])
y = c(2*dy.list[[i]] ), default.units = "native",
# Removed: ... , -rev(dy.list[[i]])
name = trellis.grobname(identifier, type = "panel",
group = group), gp = gpar(fill = col, col = border,
lty = lty, lwd = lwd, alpha = alpha))
Also remove it from the corresponding section in the else{ ...} clause. Now you can run it with the example in help(panel.violin)
还可以从else{…}条款。现在你可以用help中的例子来运行它(panel.小提琴)
bwplot(voice.part ~ height, singer,
panel = function(..., box.ratio) {
panel.violin2(..., col = "transparent",
varwidth = FALSE, box.ratio = box.ratio)
panel.bwplot(..., fill = NULL, box.ratio = .1)
} )
If you wanted the density on the other side, all you would need to do would be remove the dx.list[[i]] and dy.list[[i]] and leave in the rev(dx.list[[i]])
and -rev(dy.list[[i]])
.
如果你想要另一边的密度,你需要做的就是去掉dx。列出[i]和。列出[i],并留在rev(dx.list[i]])和-rev(dy.list[i])中。
#1
4
You can reasonably easily get the half-violin plot with fairly simple modifications to the function, panel.violin
in Sarkar's lattice package. There are four lines in that function that can be altered inside the grid.polygon
call to change from "two-sided" density plotting to single sided density plotting. First require(lattice)
and require(grid)
. Then type panel.violin
. I'll show you the "horizontal" alteration:
你可以很容易地得到半小提琴图与相当简单的修改功能,面板。萨卡尔晶格包中的小提琴。该函数中有四行可以在网格中修改。多边形要求从“双面”密度绘制变为单面密度绘制。首先需要(晶格)和要求(网格)。然后panel.violin类型。我将向你展示“水平”改变:
require(grid)
panel.violin2 <-
# snipped all the arguments and processing
grid.polygon(x = c(dx.list[[i]] ),
# Notice I removed: ... ,rev(dx.list[[i]])
y = c(2*dy.list[[i]] ), default.units = "native",
# Removed: ... , -rev(dy.list[[i]])
name = trellis.grobname(identifier, type = "panel",
group = group), gp = gpar(fill = col, col = border,
lty = lty, lwd = lwd, alpha = alpha))
Also remove it from the corresponding section in the else{ ...} clause. Now you can run it with the example in help(panel.violin)
还可以从else{…}条款。现在你可以用help中的例子来运行它(panel.小提琴)
bwplot(voice.part ~ height, singer,
panel = function(..., box.ratio) {
panel.violin2(..., col = "transparent",
varwidth = FALSE, box.ratio = box.ratio)
panel.bwplot(..., fill = NULL, box.ratio = .1)
} )
If you wanted the density on the other side, all you would need to do would be remove the dx.list[[i]] and dy.list[[i]] and leave in the rev(dx.list[[i]])
and -rev(dy.list[[i]])
.
如果你想要另一边的密度,你需要做的就是去掉dx。列出[i]和。列出[i],并留在rev(dx.list[i]])和-rev(dy.list[i])中。