本文介绍了在小提琴上准确显示stat_summary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在R上使用ggplot2,并有一个小提琴图问题。

I just started using ggplot2 on R and have a violin plot question.

我有一个数据集,可以在这里访问:。

I have a data set that can be accessed here: data.

数据来自进行估算的研究。感兴趣的变量是question.no(问题),条件,estimate.no(tr.est1或tr.est2)和估计。

The data comes from a study of making estimations. The variables of interest are the question.no (questions), condition, estimate.no (tr.est1 or tr.est2) and estimate.

下面的代码使图看起来几乎是我希望至少在一个问题上看到的样子,但是stat_summary()生成的中点显示在小提琴之间。

The code below makes the plot look almost the way I want it to look at least for one question, yet the median dots generated by stat_summary() are displayed in between the "violins."

 v.data<-read.csv("data.csv")

 # loop through each question number
 d_ply(v.data, c("question.no"), function(d.plot){
 q.no <- v.data$question.no

 plot.q <- ggplot(d.plot,aes(condition, estimate, fill=estimate.no)) +
   geom_violin() +
   stat_summary(fun.y="median", geom="point") +
   scale_y_continuous('Change Scores') +
   scale_x_discrete("Conditions")

ggsave(filename=paste(q.no,".png",sep=""))

})

我的问题:如何使中点正确显示在小提琴上而不是它们之间?

My Question: How can I make the median dots display correctly on the "violins" rather than in between them?

我搜索了之前提出的问题在该站点上的ggplot2上查看了ggplot2文档以及其他R论坛,但未能找到任何相关的内容。

I searched the previous questions asked on ggplot2 on this site and looked at the ggplot2 documentation as well as other R forums but have not been able to find anything relevant.

对于如何解决它,我将不胜感激。另外,如果我提出的问题已经在其他地方得到回答,我也非常感谢与线程的链接。提前谢谢了。

I would appreciate any comments and suggestions as to how I can fix it. Also, if the questions I ask are already answered somewhere else, I would appreciate the links to the threads,too. Many thanks in advance.

推荐答案

是基于 ggplot2 的库,旨在根据1-3个变量的特征自动选择绘图类型。对于您的数据集,命令 plotluck(v.data,condition,估计,question.no)生成以下图:

Plotluck is a library based on ggplot2 that aims at automating the choice of plot type based on characteristics of 1-3 variables. For your data set, the command plotluck(v.data, condition, estimate, question.no) generates the following plot:

注意库选择对数缩放y。您可以使用 plotluck(v.data,condition,estimate,question.no,opts = plotluck.options(trans.log.thresh = 1E20))覆盖此行为不能很好地显示,中点看起来都在零线上。

Note that the library chose to scale y logarithmically. You can override this behavior with plotluck(v.data,condition,estimate,question.no,opts=plotluck.options(trans.log.thresh=1E20)) but it doesn't display well, and the median points look like they are all on the zero line.

这篇关于在小提琴上准确显示stat_summary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:33