2017-03-01 102 views
1

豆情节和传说我有一个关于我的豆情节和传说中的问题。我无法找到一个方法来做到以下几点调整中的R

  • 改变X轴标签(从communication_focusedcommunication-focused
  • 显示更精细的方式y轴(如减免应该是从0开始,25 ,50,75,100,125 ... 300)
  • 把传说中的情节
  • 保持在传说中比我得到现在
  • 标志着在每个类别中的mean(黑色实线越大文本的字体以外)在“红”色的每个类别

这里是我的代码:

beanplot(onset_s~ group*meaning, data=mu3,ll = 0.08, 
    main = "Distribution of movement units", side = "both", 
    col = list("black", c("grey", "white")), 
    axes=T, beanlines = "median") 

legend("topleft",fill = c("grey", "black"), legend = c("Non-Performers", "Experts"), cex=0.65) 

我的数据集:

tier   meaning  onset_sgroup 
head_face_mu self_focused 0 expert 
head_face_mu self_focused 0 expert 
head_face_mu context_focused 0 expert 
upper_body_mu self_focused 0 expert 
upper_body_mu self_focused 0 expert 
head_face_mu communication_focused 0 novice 
head_face_mu context_focused 0 novice 
head_face_mu context_focused 0 novice 
upper_body_mu self_focused 0 novice 
upper_body_mu self_focused 0 novice 
upper_body_mu self_focused 0 novice 
head_face_mu self_focused 0.18 novice 
lower_body_mu self_focused 0.667 novice 
head_face_mu communication_focused 0.69 novice 
head_face_mu context_focused 1.139 novice 
head_face_mu context_focused 1.301 novice 
head_face_mu context_focused 1.32 novice 
lower_body_mu self_focused 1.66 novice 
head_face_mu context_focused 1.98 novice 
lower_body_mu self_focused 2.205 novice 
head_face_mu communication_focused 2.297 novice 
head_face_mu context_focused 2.349 novice 
lower_body_mu self_focused 2.417 novice 
upper_body_mu self_focused 2.666 novice 
head_face_mu self_focused 2.675 expert 
head_face_mu context_focused 3.218 novice 
head_face_mu context_focused 3.353 novice 
head_face_mu context_focused 3.436 expert 
head_face_mu context_focused 3.588 novice 
head_face_mu context_focused 3.697 novice 
upper_body_mu self_focused 4.006 novice 
upper_body_mu context_focused 4.033 novice 
upper_body_mu self_focused 4.06 expert 
head_face_mu context_focused 4.33 novice 
upper_body_mu self_focused 4.332 novice 
upper_body_mu self_focused 4.44 novice 
head_face_mu context_focused 4.738 novice 
lower_body_mu self_focused 5.395 novice 
head_face_mu self_focused 5.428 novice 
lower_body_mu self_focused 5.926 novice 
head_face_mu context_focused 6.283 novice 
head_face_mu context_focused 7.002 novice 
head_face_mu self_focused 7.031 novice 
lower_body_mu self_focused 7.189 novice 
upper_body_mu communication_focused 7.45 novice 
lower_body_mu self_focused 7.632 expert 1.144 
head_face_mu self_focused 7.739 expert 2.159 
lower_body_mu self_focused 8.943 novice 9.517 
head_face_mu context_focused 9.002 expert 4.608 

这是我的图:

enter image description here

任何的反馈和评论都超过欢迎!

预先感谢您。

+0

首先,当您添加数据集时可以使用'dput()'完成这项工作。其次,你应该考虑在'ggplot2'包使用'geom_violin'因为这将解决你的传奇问题。第三,为了按类别分割你的情节,你可以在这个问题[拆分小提琴情节]中看到答案(http://stackoverflow.com/questions/35717353/split-violin-plot-with-ggplot2)。最后,您可以使用'geom_line'来添加您的平均值并将其颜色设置为红色。 – tbradley

+0

@tbradley:第1点:我将自己的数据子集的50分。如果有一个选项可以将整个“.csv”文件添加到我的问题中(我的子集包含将近1000个数据点),并且您希望我这样做,请让我知道。第二和第三点。'geom_violin'情节对我来说不是一种选择,因为a)你不能看到它的个别异常值,b。)只有最小值和最大值在图上可见,以及c。)没有指示在图形表示中可以观察到一个组。 – user3832272

回答

1

嗯,我已经用它玩了一段时间,我已成功地回答你所有的问题只是改变mean线的颜色。在col = arguement在beanplot()功能集合起来似乎有点挑剔我。然而,这里是我对一切:

par(xpd=F, mai = c(1, 1, 1, 2)) 
beanplot(onset_s~ group*meaning, data=df,ll = 0.08, 
     main = "Distribution of movement units", side = "both", 
     col = list("black", c("grey", "white")), 
     axes=F, beanlines = "median", ylim = c(-5, 15)) #axes = F let's you define your own axes 

#now you can define the x and y axes like this 
#note - this also takes care of your renaming issue 
#although you could just change the character values using subsetting 
#axis 1 is the x axis 
axis(1, at = 1:3, labels = c("communication-focused", "context-focused",  "self-focused")) 

#axis 2 is the y axis, and you can change the values in the "at =" vector 
axis(2, at = c(-5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15)) 


#this creates the outer box around the plot, which is removed with axes = F 
box(which = "plot") 

#This now lets you add things to the graphic system outside of the plotting area 
par(xpd=TRUE) 

#you will need to change the x and y coordinates 
#also, the "cex =' arguement of the legend function controls 
#the size of the text, so by setting this equal to one, you achieve larger text 
legend(3.7, 15.8,fill = c("grey", "black"), legend = c("Non-Performers", "Experts"), cex=1) 

现在,我在col =论点试图内beanplot多种不同的组合,以解决您平均线的问题。然而,我所得到的最接近的是将这条线变成了红色,但随后摆脱了每个bean的分割设置。我想你应该刚刚玩不同的组合,并阅读?beanplot帮助页面的具体参数的描述。

无论如何,我希望这有助于

UPDATE我已经加入了mai = c()参数的par()第一个函数调用。此参数允许您通过以英寸为单位指定每个相应边距的边距大小(按照从底部,左侧,顶部,右侧的顺序)来控制图形周围的边距。这应该可以解决你的问题。我添加了图形图像以显示它当前的样子: enter image description here

+0

@ tbradley:非常感谢您的解决方案。一切正常,但现在我对剧情空间之外的传说有了一个新问题。在将我的'x'和'y'坐标改为'legend(3.7,365)'后,我只能看到图右上方的一点图例。看起来情节并没有缩小为传奇创造“空间”。你有什么建议如何解决它? – user3832272

+0

@ user3832272我已经做了一些编辑,可以为你解决这个问题。 – tbradley

+0

另外,因为看起来你是新手,所以如果这个答案解决了你的问题,请把它标为正确!谢谢! – tbradley