【问题标题】:grid lines for each value of a factor in lattice violin plots格子小提琴图中每个因子值的网格线
【发布时间】:2023-03-11 18:12:01
【问题描述】:

我使用 R 的 lattice 包制作了点图和小提琴图。点图对因子的每个值都有网格线,以便更容易找到相应的点。

是否可以在不显示此类线条的格子小提琴图中产生此类线条?

在我的例子中,数据分布在更广泛的范围内,因此有时更难找到因子的对应值(因为对于因子的某些值,小提琴看起来更像一个点而不是小提琴)。

这是一个使用内置数据框 mtcars 的点图(用垂直线连接点)和小提琴图(其中“小提琴”与因子的值没有图形连接)的最小示例:

library("lattice")
dotplot( mpg ~ as.factor( cyl ), data=mtcars )
bwplot( mpg ~ as.factor(cyl), data=mtcars, panel = function( ..., box.ratio ) { panel.violin( ..., box.ratio ) } )

【问题讨论】:

标签: r lattice


【解决方案1】:

这应该在小提琴图后面加上灰线:

bwplot( mpg ~ as.factor(cyl), data=mtcars, 
  panel = function(x, y, ..., box.ratio ) {
    panel.abline(v = x, col = "gray")
    panel.violin(x, y, ..., box.ratio ) 
  } )

【讨论】:

    猜你喜欢
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    相关资源
    最近更新 更多