简体   繁体   English

如何使用子集在R中绘制bloxplot

[英]How to plot a bloxplot in R with subsets

My data set "olympics" has 4 columns: case number, height, sport, and sex (female=F, male=M), and each row corresponds to an athlete. 我的数据集“奥运”有4列:病例数,身高,运动和性别(女性= F,男性= M),每行对应一名运动员。

I need to produce a box plot comparing the height distributions among the male basketball players and male football players. 我需要制作一个比较男子篮球运动员和男子足球运动员之间高度分布的箱形图。 (Both sports on a single plot, but with no others.) (两个运动都在一个地块上,但没有其他运动。)

I have tried 我努力了

boxplot(olympics$height[olympics$sex == "M" & olympics$sport %in% c("basketball", "football")])

but I keep getting errors saying that finite ylim values are needed. 但我不断收到错误,说需要有限的ylim值。 How would you get the correct boxplot? 你会如何得到正确的箱形图?

Going to rewrite this since I found your data set and figured out what your issue was. 要重写这个,因为我找到了你的数据集,并找出了你的问题。 You have a ton of typos. 你有大量的错别字。 R is case sensitive. R区分大小写。 Run this code and it will produce the boxplots that you want. 运行此代码,它将生成您想要的箱图。

library(VGAMdata)
data(oly12)

dat = oly12

dat = dat[dat$Sport %in% c("Basketball","Football"),]
dat$Sport = droplevels(dat$Sport)
dat = dat[dat$Sex == "M",]
boxplot(dat$Height ~ dat$Sport)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM