本文介绍了R程序上的BoxPlot具有特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为R的新手,我想到了一些问题。你们能帮我吗?
Being new to R, I have some problems in mind. Can you guys help me with it?
我有一系列数据
X Gender Score Postal
1 F 427.395 123455
2 F 922.080 642362
3 M 114.500 123947
4 M 176.345 236835
5 F 523.140 849729
以上是500个数据的样本。
Above is a sample of 500 data.
我希望分别对男女得分做一个箱形图。但是,邮政编码也会在箱线图中捕获。我该如何为boxplot创造条件,使其仅从X和Score中捕获按性别分类的数据?
I wish to do a boxplot on scores for females and males separately and also. However, there's the postal code which will be captured in the boxplot as well. How do I make the conditions for boxplot to capture data from only X and Score, classified by gender?
我试图在绘制boxplot之前先进行排序,但是可以吗?似乎没有用。你们对此有什么想法吗?
I have tried to do sorting first before plotting boxplot, but can't seem to make it work. Do you guys have any ideas on this?
谢谢!
推荐答案
调用数据 df
,使用:
boxplot(Score~Gender,data=df)
使用ggplot:
library(ggplot2)
ggplot(df) + geom_boxplot(aes(x=Gender, y=Score, color=Gender))
这篇关于R程序上的BoxPlot具有特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!