[英]Create a bar plot with 2 columns of a data frame in the x-axis in R
我有一個數據框的 2 列說
t1=data.frame(c1=c("Y","N","U","Y","N","U"),c2=c("Y","N","N","U","U","Y"))
我想創建一個條形 plot ,其中 x 軸上的兩列以及 Y、N 和 U 的出現次數作為每列的 3 個單獨的條。 謝謝!
這是使用tidyverse
實現此目的的選項:
library(tidyverse)
t1 %>% pivot_longer(everything(), names_to = "name", values_to = "Let") %>%
ggplot(aes(x=name, fill=Let))+
geom_bar(position="dodge")
library(tidyverse)
t1 %>% pivot_longer(everything(), names_to = "name", values_to = "Let") %>%
ggplot(aes(x=Let, fill=name))+
geom_bar()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.