我有这个数据
A <- c(100,101,102,98,97,93,96)
B <- c("John","Anne","John", "Anne","John","Anne","John")
C <- c("cheap", "cheap", "expensive", "cheap", "expensive", "cheap", "expensive")
D <- c("USA", "Mexico", "Mexico","USA", "Mexico","USA", "Mexico")
dataframe <- data.frame(A, B, C, D)
A B C D
1 100 John cheap USA
2 101 Anne cheap Mexico
3 102 John expensive Mexico
4 98 Anne cheap USA
5 97 John expensive Mexico
6 93 Anne cheap USA
7 96 John expensive Mexico假设我想在相同的图上创建不同的盒子图,分组B、C和D列。
因此,总共有6个剧集(约翰、安妮、廉价、昂贵、美国和墨西哥)。当然,考虑到A组的值。
这里的问题是,每个子组都有不同的样本来绘制,这让我非常困惑。
发布于 2022-02-02 16:15:48
这个问题是reshaping the data to long format的问题。然后它就成了标准的盒子。
library(ggplot2)
library(magrittr)
library(tidyr)
dataframe %>%
pivot_longer(-A) %>%
ggplot(aes(value, A)) +
geom_boxplot()

https://stackoverflow.com/questions/70958840
复制相似问题