小提琴图未按预期工作

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

我正在尝试为给定的数据集生成小提琴图.数据从0到100不等.但小提琴图超过100而低于0.

I am trying to generate a violin plot for a given dataset. The data varies from 0 to 100. But the violin plot goes over 100 and goes below 0.

如何将其限制在0到100之间?

How can I limit it between 0 to 100?

使用的代码:

library(ggplot2) input_data <- read.csv("C:/Temp/Recall.csv") input_data precision_in_percentage <- input_data$ResultValue # Basic violin plot p <- ggplot(input_data, aes(x='TRAssociation', y=precision_in_percentage)) + geom_violin(trim=FALSE) + geom_violin(trim=FALSE, fill='#A4A4A4', color="darkred")+ geom_boxplot(width=0.05) + theme_minimal() p

小提琴图:

推荐答案

检查geom_violin()的文档,看来您应该删除trim=False规范.默认情况下,ggplot2设置trim = True.

Checking the documentation for geom_violin(), it looks like you should remove the trim=False specification. By default, ggplot2 sets trim = True.

来自ggplot2 文档:

From ggplot2 docs:

trim:如果为TRUE(默认值),则将小提琴的尾部修整到该范围 的数据.如果 假,不要修剪尾巴.

trim: If TRUE (default), trim the tails of the violins to the range of the data. If FALSE, don't trim the tails.

请注意,如果您喜欢geom_violin()的形状,并且只想限制y轴边界,则可以通过在绘图函数调用中添加+ ylim(0, 100)来实现.

Note that if you like the shape of the geom_violin() and just want to restrict the y-axis boundaries, you can do that by adding + ylim(0, 100) to your plotting function calls.

此外,请注意,有一个箱线图工具可以更好地与通过stat_summary()功能提供的小提琴图一起演奏.尝试删除对geom_boxplot()的呼叫,而改用此呼叫(您可能想使用shape和size参数:

Also, note that there is a boxplot tool that plays better with violin plots available via the stat_summary() function. Try removing your call to geom_boxplot() and instead using this (you may want to play with the shape and size parameters:

+ stat_summary(fun.y=median, geom="point", fill="white", shape=21, size=2.5)

更多推荐

小提琴图未按预期工作

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

发布评论

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

>www.elefans.com

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