how to draw paired boxplot in R
时间: 2024-02-06 07:12:20 浏览: 139
To draw paired boxplots in R, you can use the `ggplot2` package. Here is an example code:
```R
library(ggplot2)
# create sample data
data <- data.frame(
group = rep(c("A", "B"), each = 50),
value = c(rnorm(50, 10, 2), rnorm(50, 12, 2))
)
# plot paired boxplot
ggplot(data, aes(x = group, y = value, fill = group)) +
geom_boxplot() +
labs(title = "Paired Boxplot", x = "Group", y = "Value")
```
This code will create a paired boxplot with two groups labeled as "A" and "B". The `geom_boxplot()` function from `ggplot2` is used to create the boxplots. The `fill` parameter in `aes()` is used to fill the boxes with different colors for each group. The `labs()` function is used to add a title and axis labels to the plot.
阅读全文
相关推荐


















