I want to express the frequency of each column (a,b,c,d,e) in a graph of (t) for each group. I don't know what to do. As shown in the figure, the data was selected in the form of a data frame, but I don't know what to do when I express it in the next graph. I tried to extract only the value for a with ggplot, but even this didn't work out. Is there a good way? Is there a way to express it with lines other than bar graphs? Help me.
CodePudding user response:
Pivot the data longer to merge all counts of columns a to e inside just one name and value column, which can be used as dimension aesthetics for ggplot:
library(tidyverse)
data <- tribble(
~t, ~a, ~b,
"m", 300, 100,
"i", 20, 44,
"j", 15, 99
)
data %>%
pivot_longer(-t) %>%
ggplot(aes(t, value, fill = name))
geom_col(position = "dodge")