-4

enter image description here

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

jazzurro
  • 23,179
  • 35
  • 66
  • 76
pingu
  • 31
  • 2
  • 1
    Please share you code. and be precise, here I don't see categorical variable in each coloumn but numbers... – timat Jan 10 '17 at 10:12

2 Answers2

0

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.

Community
  • 1
  • 1
McGrady
  • 10,869
  • 13
  • 47
  • 69
0

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.

Wietze314
  • 5,942
  • 2
  • 21
  • 40