我可以用这些数据制作箱线图吗?

Can I make a boxplot with this data?

我不确定是否必须更改数据格式才能制作箱线图。 我的数据如下所示:

Land   Income 1999 Income 2019
Spain    5             7
France   4             8
Greece   3             5
...

现在我想做两个箱线图来比较1999年和2019年的收入。 那可能吗? 我不知道我应该如何选择轴。

提前致谢

无需重新格式化数据,您可以直接创建箱线图。假设您的数据位于名为 df:

的 table 中
boxplot(df[, -1L])

ggplot2 的方法:

library(tidyverse)

df <- data.frame(
  country = c("Spain", "france", "Portugal"),
  "income_1999" = c(9,8,7),
  "income_2019" = c(11,10,9)
  
)

df %>% 
  pivot_longer(-country, names_to = "income", values_to = "amount") %>% 
  ggplot(aes(x=income, y=amount)) +
  geom_boxplot()

reprex package (v2.0.0)

于 2021-10-19 创建