简体   繁体   English

R - 在同一 plot 中绘制多个具有相同比例/索引的不同变量的箱线图

[英]R - Drawing multiple boxplots of different variables with the same scale / index in the same plot

Lets say I have 2 Variables with 20 data points each (0,1,2 or 3) and I want to plot boxplots of each of the variables but so that they share the y-axis in a diagram.假设我有 2 个变量,每个变量有 20 个数据点(0、1、2 或 3),我想要 plot 每个变量的箱线图,但这样它们在图中共享 y 轴。 How do I do this easily?我如何轻松做到这一点?

Writing boxplot(var1,var2,data = mydata) didn't work...boxplot(var1,var2,data = mydata)没有用...

You should provide reproducible data and you should tell us what error message(s) you received with your code.您应该提供可重现的数据,并且应该告诉我们您的代码收到了哪些错误消息。 When a function does not perform as expected, it is good to read the manual page ( ?boxplot ).当 function 未按预期执行时,最好阅读手册页 ( ?boxplot )。 Here are some made-up data similar to yours:以下是一些与您类似的虚构数据:

set.seed(42)
mydata <- data.frame(var1=sample(0:3, 20, replace=TRUE), var2=sample(0:3, 20, replace=TRUE))

Then the box plot is just那么盒子plot就是

boxplot(mydata)  # Or boxplot(mydata[, c("var1", "var2")]) if you are excluding other columns

箱形图

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

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