[英]Using R to create boxplot with 2 variables on X axis
I am fairly new to R and want to combine 2 basic box plots into 1. 我对R相当陌生,想将2个基本箱形图合并为1个。
My code so far is... 到目前为止,我的代码是...
library(tidyverse)
library(vegan)
spiders <- read_csv(file = "Spider Data.csv")
class(spiders)
str(spiders)
boxplot(spiders$Length_mm ~ spiders$Distance)
boxplot(spiders$Length_mm ~ spiders$Cover)
Here are the plots I have so far as well as something like what I want to create (ignore the label names in the coloured graph, I just took the picture from google, but I want something similar) 这是我到目前为止的绘图以及类似我想要创建的绘图(忽略彩色图形中的标签名称,我只是从Google拍摄照片,但我想要类似的东西)
my first boxplot 我的第一个箱线图
my second boxplot 我的第二个箱线图
what I want my graph to look like (ignore labels) 我想让我的图表看起来像什么(忽略标签)
If you wan tto stay with base R, and not other plot library, you can use at=
in boxplots to say where the boxes should be displayed and col=
to set different colors. 如果要保留基数R,而不是其他图库,则可以在框图中使用at=
来表示应在何处显示框,而col=
可以设置不同的颜色。 This would give for example: 例如:
library(tidyverse)
library(vegan)
spiders <- read_csv(file = "Spider Data.csv")
class(spiders)
str(spiders)
boxplot(spiders$Length_mm ~ spiders$Distance, at=c(0.85,1.85), col=2, names="Good")
boxplot(spiders$Length_mm ~ spiders$Cover, at=c(1.15,2.15), col=3, names="Bad")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.