数据框的小提琴图

编程入门 行业动态 更新时间:2024-10-09 20:23:58
本文介绍了数据框的小提琴图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个data.frame,例如:

df = data.frame(AAA=rnorm(100,1,1),BBB=rnorm(100,2,1.5),CCC=rnorm(100,1.5,1.2))

我想在一个联合小提琴图中绘制它的每一列.

And I'd like to plot each of its columns in a joint violin plot.

这是我目前所处的位置:

Here's where I'm at so far:

names(df)[1] = 'x' do.call('vioplot', c(df,col="red",drawRect=FALSE))

我接下来要做的是将 df 的列名绘制为 x 轴标签而不是 vioplot 的默认 x 轴标签,此外还有一个这样他们就不会互相碾压.我想这可以通过在图中展开 df 的列或倾斜 x 轴标签来实现.但我想不通.

What I want to do next is to plot the colnames of df as x-axis labels rather than the default x-axis labels of vioplot and in addition in a way that they don't run over each other. I imagine this can be achieved either by spreading the columns of df in the plot or by slanting the x-axis labels. But I can't figure that out.

推荐答案

可能更容易使用 ggplot

Probably easier to use ggplot

df = data.frame(AAA=rnorm(100,1,1), BBB=rnorm(100,2,1.5), CCC=rnorm(100,1.5,1.2))

需要将数据转换成ggplot可以处理的东西:

Need to transform the data into something ggplot can handle:

df.m <- reshape2::melt(df, id.vars = NULL)

和情节:

library(ggplot2) ggplot(df.m, aes(x = variable, y = value)) + geom_violin()

更多推荐

数据框的小提琴图

本文发布于:2023-07-18 08:18:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小提琴   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!