[英]I am trying to to put 5 boxplot graphs in R. Each of them come out really squished. How do I fix this?
[英]R: Two columns and trying to make a density or boxplot. How do I stack them
我有一個基本上如下所示的數據框
score1 score2
1 1
2 2
3 3
4 4
5 5
它們代表兩個不同的群體,我正在嘗試創建一個箱線圖來並排比較它們。 是否有 a) 一種使用這些數據生成箱線圖或密度圖的方法,或者 b) 一種將它們堆疊在一起以生成可用於制作此類圖的數據框的方法? 這是數據框:
score1 <- c(1,2,3,4,5)
score2 <- c(1,2,3,4,5)
df <- data.frame(score1, score2)
這是一個tidyverse方法。 使用pivot_longer
將分數標簽和值分成單獨的列。 然后疊加或分面圖進行比較。
覆蓋
library(tidyverse)
df %>%
pivot_longer(everything()) %>%
ggplot(aes(value, color = name)) +
geom_density() # changed score2 to c(1,2,3,4,8) to show differences
df %>%
pivot_longer(everything()) %>%
ggplot(aes(value)) +
geom_density() +
facet_wrap(~name)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.