Hello!
I have a table like it:
A B
1 55
1 43
2 55
1 89
3 55
4 43
4 55
I would like to count for each column the frequency of each categorical value and plot them like in figure.
How can I do it?
Thank you in advance
Hello!
I have a table like it:
A B
1 55
1 43
2 55
1 89
3 55
4 43
4 55
I would like to count for each column the frequency of each categorical value and plot them like in figure.
How can I do it?
Thank you in advance
I suggest ggplot2 to get your barplot.
Check out this How to Make a Stacked Bar Chart in R Using ggplot2.
Read the ggplot docs and have a try.
By the way ,it's good for you to read how to ask.
Hope this helps.
I do not fully get how your table produces the plot you provide since both columns have equal values, and the plot has 9 vs 6 values.
With R base you could try:
df <- data.frame( A = c(1,1,2,1,3,4,4),
B = c(55,43,44,89,55,43,55))
df2 <- data.frame(cat = rep(c("A","B"),each=nrow(df)), val = c(df$A,df$B))
barplot(as.matrix(table(df2$val,df2$cat)))
You would need some additional work on the data to get the colors between A and B similar. Since A and B have different types of values, the plot now has 6 different colors.